Skip to content

Commit

Permalink
Improved error reporting when deserializing a non-existent record (e.…
Browse files Browse the repository at this point in the history
…g. because it was deleted).
  • Loading branch information
tompave committed Aug 17, 2014
1 parent 6fc9000 commit 51b0cfc
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/delayed/psych_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,17 @@ def visit_Psych_Nodes_Mapping_with_class(object) # rubocop:disable CyclomaticCom
id = payload['attributes'][klass.primary_key]
begin
klass.unscoped.find(id)
rescue ActiveRecord::RecordNotFound
raise Delayed::DeserializationError
rescue ActiveRecord::RecordNotFound => error
raise Delayed::DeserializationError, "ActiveRecord::RecordNotFound, class: #{klass}, primary key: #{id} (#{error.message})"
end
when /^!ruby\/Mongoid:(.+)$/
klass = resolve_class(Regexp.last_match[1])
payload = Hash[*object.children.collect { |c| accept c }]
id = payload['attributes']['_id']
begin
klass.find(payload['attributes']['_id'])
rescue Mongoid::Errors::DocumentNotFound
raise Delayed::DeserializationError
klass.find(id)
rescue Mongoid::Errors::DocumentNotFound => error
raise Delayed::DeserializationError, "Mongoid::Errors::DocumentNotFound, class: #{klass}, primary key: #{id} (#{error.message})"
end
when /^!ruby\/DataMapper:(.+)$/
klass = resolve_class(Regexp.last_match[1])
Expand All @@ -61,8 +62,8 @@ def visit_Psych_Nodes_Mapping_with_class(object) # rubocop:disable CyclomaticCom
primary_keys = klass.properties.select { |p| p.key? }
key_names = primary_keys.collect { |p| p.name.to_s }
klass.get!(*key_names.collect { |k| payload['attributes'][k] })
rescue DataMapper::ObjectNotFoundError
raise Delayed::DeserializationError
rescue DataMapper::ObjectNotFoundError => error
raise Delayed::DeserializationError, "DataMapper::ObjectNotFoundError, class: #{klass} (#{error.message})"
end
else
visit_Psych_Nodes_Mapping_without_class(object)
Expand Down

0 comments on commit 51b0cfc

Please sign in to comment.