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

Promise.reject results in UnhandledRejectionError #1629

Closed
stephenprater opened this issue Jan 30, 2020 · 4 comments
Closed

Promise.reject results in UnhandledRejectionError #1629

stephenprater opened this issue Jan 30, 2020 · 4 comments

Comments

@stephenprater
Copy link

Description

Calling Promise.reject() from within a handler function results in an UnhandledRejectionError

Minimal, Working Test code to reproduce the issue.

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

Bull version

3.12.1

Additional information

Using done(new Error('oh no') does not result in this error.

@stephenprater
Copy link
Author

Duh. return Promise.reject(new Error('oh no'))

@Hikariii
Copy link

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

@manast
Copy link
Member

manast commented Sep 28, 2020

@Hikariii is it not handled? I think the original code was lacking a return, therefore the "Duh". :)

@Hikariii
Copy link

Nope it is not. Throwing an error goes fine, but returning a rejected promise with an error gives an unhandled promise rejection error.

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

No branches or pull requests

3 participants