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
Preserve Error object properties when job fails #40
Comments
I recall giving this some consideration and leaving it as a "that can probably get tricky if I go further, this'll do." While more faithful preservation can certainly be useful, if we preserve more about the error, we have to ask "well, what exact use cases do we try to support and how much do we try to preserve in this aspect or that aspect?" Do we try to serialize whether an Error was a ReferenceError or a TypeError? Is that what you mean by Partially motivated by wanting to dodge the above slew of questions, I decided originally that since the |
Well, the idea is to do it in a non-opinionated way. There are two cases:
|
ok I'm back home with keyboard, I can be a bit more specific. The var queue = new Queue('foo', {
...
serializeError: (err => ({
name: err.name,
message: err.message,
stack: err.stack
})),
deserializeError: null, // Nothing by default, although something could be worked out but not critical
...
}); Then, when you are done processing the job: process(job, (err, res) => {
...
err = (err instanceof Error) ? opts.serializeError(err) : err;
err = JSON.stringify(err);
....
}); And when invoking the callback you would do: job.emit('failed', (opts.deserializeError) ? opts.deserializeError(err) : err)) Hope I made things a bit clearer ^^;; |
Merging with #146.
|
Is there no way to easily retrieve error details then, without having to serialize via the error.message |
Is there any progress on this? I really like @perrin4869's solution from #41 but it seems not to have been approved. This issue is causing me a fair bit of trouble right now. |
As it stands right now, when a job fails, the only part of the error that is preserved is the message.
I think that the error should be serialized in a manner similar to the job result. If the error is a json object, then it is passed to
job.on('failed', err => { ... })
as is. If the error is anError
object, then it gets serialized. I propose that forerr instanceof Error
, the serialization would beerr => ({ name: err.name, message: err.message })
I can try to put together a pull request to get this done too.
The text was updated successfully, but these errors were encountered: