From cb1af2a10568cf4c9e5a593744077166b4676ba7 Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Thu, 5 Dec 2024 12:54:41 +0100 Subject: [PATCH] Fixes #38068 - Consistently use errors.add Using `errors[:field] << 'the error'` is deprecated in favor of `errors.add(:field, 'the error')`. Instances found using: rg 'errors\[.+\]\s+<<' --- app/controllers/usergroups_controller.rb | 2 +- app/models/compute_resources/foreman/model/ec2.rb | 4 ++-- app/models/compute_resources/foreman/model/libvirt.rb | 2 +- app/models/compute_resources/foreman/model/openstack.rb | 2 +- app/models/compute_resources/foreman/model/vmware.rb | 2 +- app/services/host_build_status.rb | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/controllers/usergroups_controller.rb b/app/controllers/usergroups_controller.rb index b633f906739..4079b29ffe8 100644 --- a/app/controllers/usergroups_controller.rb +++ b/app/controllers/usergroups_controller.rb @@ -37,7 +37,7 @@ def update process_error end rescue Foreman::CyclicGraphException => e - @usergroup.errors[:usergroups] << e.record.errors[:base].join(' ') + @usergroup.errors.add(:usergroups, e.record.errors[:base].join(' ')) process_error rescue => e external_usergroups_error(@usergroup, e) diff --git a/app/models/compute_resources/foreman/model/ec2.rb b/app/models/compute_resources/foreman/model/ec2.rb index 930b3316b60..d801542190a 100644 --- a/app/models/compute_resources/foreman/model/ec2.rb +++ b/app/models/compute_resources/foreman/model/ec2.rb @@ -122,9 +122,9 @@ def test_connection(options = {}) super errors[:user].empty? && errors[:password].empty? && regions rescue Fog::AWS::Compute::Error => e - errors[:base] << e.message + errors.add(:base, e.message) rescue Excon::Error::Socket => e - errors[:base] << e.message + errors.add(:base, e.message) end def console(uuid) diff --git a/app/models/compute_resources/foreman/model/libvirt.rb b/app/models/compute_resources/foreman/model/libvirt.rb index 123f1a18e26..1f50ec8a837 100644 --- a/app/models/compute_resources/foreman/model/libvirt.rb +++ b/app/models/compute_resources/foreman/model/libvirt.rb @@ -78,7 +78,7 @@ def test_connection(options = {}) errors[:url].empty? && hypervisor rescue => e disconnect rescue nil - errors[:base] << e.message + errors.add(:base, e.message) end def new_nic(attr = {}) diff --git a/app/models/compute_resources/foreman/model/openstack.rb b/app/models/compute_resources/foreman/model/openstack.rb index 3a414cfa4a3..44154ace9f8 100644 --- a/app/models/compute_resources/foreman/model/openstack.rb +++ b/app/models/compute_resources/foreman/model/openstack.rb @@ -91,7 +91,7 @@ def test_connection(options = {}) super errors[:user].empty? && errors[:password] && tenants rescue => e - errors[:base] << e.message + errors.add(:base, e.message) end def available_images diff --git a/app/models/compute_resources/foreman/model/vmware.rb b/app/models/compute_resources/foreman/model/vmware.rb index 76c7ea8e9ee..1a5284f454e 100644 --- a/app/models/compute_resources/foreman/model/vmware.rb +++ b/app/models/compute_resources/foreman/model/vmware.rb @@ -470,7 +470,7 @@ def test_connection(options = {}) errors.delete(:datacenter) end rescue => e - errors[:base] << e.message + errors.add(:base, e.message) end def parse_args(args) diff --git a/app/services/host_build_status.rb b/app/services/host_build_status.rb index 71406ac605d..9450bca793c 100644 --- a/app/services/host_build_status.rb +++ b/app/services/host_build_status.rb @@ -56,6 +56,6 @@ def smart_proxies_status def fail!(type, message, id = nil) @state = false - @errors[type] << {:message => message, :edit_id => id} + @errors.add(type, {:message => message, :edit_id => id}) end end