Skip to content

Commit

Permalink
Fixes #38068 - Consistently use errors.add
Browse files Browse the repository at this point in the history
Using `errors[:field] << 'the error'` is deprecated in favor of
`errors.add(:field, 'the error')`. Instances found using:

    rg 'errors\[.+\]\s+<<'
  • Loading branch information
ekohl committed Dec 5, 2024
1 parent 76dcbbe commit cb1af2a
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/controllers/usergroups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions app/models/compute_resources/foreman/model/ec2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion app/models/compute_resources/foreman/model/libvirt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {})
Expand Down
2 changes: 1 addition & 1 deletion app/models/compute_resources/foreman/model/openstack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/compute_resources/foreman/model/vmware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion app/services/host_build_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit cb1af2a

Please sign in to comment.