Bull passing error.cause to failed handlers
Created by: gabegorelick
Description
When failing a job with an Error, Bull attempts to grab the error's cause:
However, there's no guarantee cause
will be an instance of Error. In fact, if you pass a VError
, cause
will be a function that returns the cause. This causes (no pun intended) Bull to pass incorrect values to any failed
handler.
I'm also not sure why Bull would want to return the cause and obscure the higher level error in the first place. If I'm passing a wrapped Error as the failure, surely that means I want that error to be returned, and not the lower level error. EDIT: there's a handy test case that explains the rationale: https://github.com/OptimalBits/bull/blob/cf2c6883fc2d861397bd59df7186b730800655e0/test/test_queue.js#L1213
Minimal, Working Test code to reproduce the issue.
const Queue = require('bull');
const VError = require('verror');
const queue = new Queue('foo');
queue.process('job', (job, callback) => {
callback(new VError(new Error('root cause'), 'wrapper message'));
});
queue.on('failed', (job, err) => {
console.log(err.stack); // prints `undefined`
process.exit();
});
queue.add('job', {});
Bull version
3.4.8