Calling Promise.reject() from within a handler function results in an UnhandledRejectionError
const Queue = require('bull');
const queue = new Queue('test');
queue.process('job', 1, job => {
console.log('tryna process');
Promise.reject(new Error('oh no'));
});
queue.add('job', {});
setInterval(() => console.log('tick'), 1000);
Output:
tryna process
(node:62747) UnhandledPromiseRejectionWarning: Error: oh no
at Queue.<anonymous> (/Users/stephenprater/src/fandango/hermes/test.js:6:18)
at handlers.<computed> (/Users/stephenprater/src/fandango/hermes/node_modules/bull/lib/queue.js:656:42)
at Queue.processJob (/Users/stephenprater/src/fandango/hermes/node_modules/bull/lib/queue.js:1050:22)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
(node:62747) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:62747) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
tick
tick
tick
tick
3.12.1
Using done(new Error('oh no') does not result in this error.
Duh. return Promise.reject(new Error('oh no'))
Don't get your duh... It's completely valid to return a rejection: https://github.com/OptimalBits/bull#using-promises
This should be handled by bull imho
@Hikariii is it not handled? I think the original code was lacking a return, therefore the "Duh". :)
Nope it is not. Throwing an error goes fine, but returning a rejected promise with an error gives an unhandled promise rejection error.
Most helpful comment
@Hikariii is it not handled? I think the original code was lacking a return, therefore the "Duh". :)