Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved error reporting when deserializing a non-existent record #685

Closed
wants to merge 2 commits into from

Conversation

tompave
Copy link

@tompave tompave commented Aug 17, 2014

DelayedJob raises an overly generic Delayed::DeserializationError when it tries to load a serialized record that does not exist in the DB.
This situation can come to be because of a serialization error, or because the record has been deleted since the job was enqueued.

The error is raised because the default YAML behaviour of loading an object is patched to call klass.find(id) if the serialized object comes from a recognized persistence library (e.g. ActiveRecord).

There have already been discussions about this behaviour: #231, #282 and #296.
It seems like the DJ leads have a strong opinion on this design decision, and no patch has been merged in yet.

I'm not here to argue with the current behaviour and its implications and side effects, but I think we can do something about the error messages to make it clearer what is going on. At the moment DJ is catching the correct errors (e.g. ActiveRecord::RecordNotFound), but it's also completely discarding any information that comes with them.

This PR adds more descriptive error messages, borrowing from what has already been done here.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.09%) when pulling 51b0cfc on tompave:error_messages into 6fc9000 on collectiveidea:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.09%) when pulling 1ce8cb6 on tompave:error_messages into 6fc9000 on collectiveidea:master.

@tompave
Copy link
Author

tompave commented Aug 17, 2014

I fixed the offenses pointed out by Rubocop.
There are still 3 that make the build fail on Travis, but they are not introduced by my changes.
The tests are green.

rescue ActiveRecord::RecordNotFound
raise Delayed::DeserializationError
rescue ActiveRecord::RecordNotFound => error
raise(Delayed::DeserializationError.new("ActiveRecord::RecordNotFound, class: #{klass}, primary key: #{id} (#{error.message})"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second argument for raise is the message. Use that instead of the .new syntax.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did (in the initial commit), but rubocop flagged it.
It expressly suggested the raise(Error.new("msg")) syntax, so I updated the PR.

I see that it's also used elsewhere in the project.

The other warnings from rubocop are not caused by changes introduced in this PR.

@albus522
Copy link
Member

albus522 commented Sep 4, 2014

Manually merged 5301862

@albus522 albus522 closed this Sep 4, 2014
@tompave
Copy link
Author

tompave commented Sep 10, 2014

ok, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants