Skip to content

Commit

Permalink
Catch errors deserializing marshalled objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Novak authored and afn committed Jan 2, 2018
1 parent c7a42fb commit 5a819c2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/delayed/psych_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ def visit_Psych_Nodes_Mapping(object) # rubocop:disable CyclomaticComplexity, Me
raise Delayed::DeserializationError, "DataMapper::ObjectNotFoundError, class: #{klass} (#{error.message})"
end
else
super
begin
super
rescue Exception => error
raise Delayed::DeserializationError, "#{error.class}, class: #{klass} (#{error.message})"
end
end
end

Expand Down
10 changes: 10 additions & 0 deletions spec/psych_ext_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,14 @@
expect(deserialized).to eq(BigDecimal('13.37'))
end
end

context 'errors' do
it 'raises a DeserializationError' do
yaml = <<-YAML
--- !ruby/marshalable:Delegator
:__v2__:
YAML
expect { Psych.load_dj(yaml) }.to raise_error Delayed::DeserializationError
end
end
end

0 comments on commit 5a819c2

Please sign in to comment.