zino
zino

Reputation: 1612

What is a "false positive" rejected promise? possiblyUnhandledRejection?

Im using the Bluebird promise library in node.

I have a section in my code that catches a rejected promise and does not re-throw it.

"unhandledRejection" is still triggered with that same promise afterwards - why is this when it has already been handled?

What is a "possiblyUnhandledRejection"?

http://bluebirdjs.com/docs/api/error-management-configuration.html

However because it is possible to handle a rejected promise at any time in the indeterminate future, some programming patterns will result in false positives. Because such programming patterns are not necessary and can always be refactored to never cause false positives, we recommend doing that to keep debugging as easy as possible.

What are the "programming patterns" mentioned here?

Is this related to this pattern (one rejected promise is chained twice or more and one of them does not catch): https://github.com/petkaantonov/bluebird/issues/695#issuecomment-155373565

Thanks

Upvotes: 2

Views: 690

Answers (1)

Bergi
Bergi

Reputation: 664548

The mentioned programming practices involve installing the error handler only after the error already occurred. For an example, take

var a = Promise.delay(Math.random()*1000)
        .then(function(){ throw new Error(); });
var b = Promise.delay(Math.random()*1000)
        .then(function() { return a; })
        .catch(function() { console.log("It's ok."); });

In about half the cases, a's delay is shorter than b's, and we'll get an unhandledRejection warning.

Is this related to the pattern where one rejected promise is chained twice or more and one of them does not catch?

No, that's simply a bug. All branches need to have an error handler.

Upvotes: 3

Related Questions