Improve error on unknown role in accessories config.

Previously when unknown role (or with typo) was placed in accessories.roles,
this error was thrown: `ERROR (NoMethodError): undefined method `hosts' for nil`.
This commit is contained in:
Wojciech Wnętrzak
2024-11-05 14:41:40 +01:00
parent 9cf8da64c4
commit e4ab2a0d24

View File

@@ -176,7 +176,9 @@ class Kamal::Configuration::Accessory
def hosts_from_roles def hosts_from_roles
if accessory_config.key?("roles") if accessory_config.key?("roles")
accessory_config["roles"].flat_map { |role| config.role(role).hosts } accessory_config["roles"].flat_map do |role|
config.role(role)&.hosts || raise(Kamal::ConfigurationError, "Unknown role in accessories config: '#{role}'")
end
end end
end end