question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unhandled rejection occurs when not chained

See original GitHub issue
  1. What version of bluebird is the issue happening on? 3.5.0
  2. What platform and version? (For example Node.js 0.12 or Google Chrome 32) Chrome 58 - jsfiddle
  3. Did this issue happen with earlier version of bluebird? Yes

It seems that chaining then, catch, and finally properly handles rejection, but when the calls to then, catch, and finally are not chained an unhandled rejection is thrown. I have a jsfiddle here.

var promiseCBs = [];

var promise1 = new Promise((resolve, reject) => {
	promiseCBs.push({resolve, reject});
});
var promise2 = new Promise((resolve, reject) => {
	promiseCBs.push({resolve, reject});
});

promise1.then(() => console.log('a'));
promise1.catch(() => console.log('b'));
promise1.finally(() => console.log('c'));

promise2.then(() => console.log('1'))
	.catch(() => console.log('2'))
  .finally(() => console.log('3'));

//unhandled rejection
promiseCBs[0].reject(new Error('rej0'));

//no unhandled rejection
promiseCBs[1].reject(new Error('rej1'));

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
bstutskycommented, Jun 19, 2017

Interesting, I didn’t realize this previously. Thanks for the knowledge!

0reactions
benjamingrcommented, Sep 24, 2017

Multicast semantics are fundamental to promises, this is part of the spec and you can create a model that only allows one continuation (in JS those are typically called “tasks”).

Multicast semantics are fundamental in the design of promises. In practice if promises were unicast then things like unhandled rejections and cancellation become a lot simpler at the expense of the end user.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unhandled Rejection Error - why? // Promise Chain Design ...
When you chain the catch directly to promise , it does not apply to the promise that is coming back from the then...
Read more >
Node incorrectly throws ERR_UNHANDLED_REJECTION on ...
In your particular case the code is not ok since .then(someFn) creates a rejected promise chain and the rejection isn't handled. You can...
Read more >
Creating a JavaScript promise from scratch, Part 7: Unhandled ...
Rejected promises without rejection handlers can hide important errors, which is why both Node.js and browsers have a way of tracking them.
Read more >
Microtasks - The Modern JavaScript Tutorial
An “unhandled rejection” occurs when a promise error is not handled at the end of the microtask queue. Normally, if we expect an...
Read more >
Tracking unhandled rejected Promises - 2ality
One risk is that rejections may get lost, leading to silent failures. ... Node.js does not report unhandled rejections, but it emits events ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found