-
Notifications
You must be signed in to change notification settings - Fork 395
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
Misleading unhandled rejection warning when using when.settle #493
Comments
Hi, I've seen some reports like this in Node.js proper. Can you compare your output to the one that you would get if you left out any when.js references and replaced the |
I'm not sure what dummy functions would accomplish, because if you don't handle the rejection you get this output: > Promise.reject('help')
Promise { <rejected> 'help' }
> (node:27570) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3): help But I'd expect > const settle = (promises) => {
... return Promise.all(promises.map( p => {
..... return p.then( result => ({ state: 'fulfilled', result })).catch( error => ({ state: 'rejected', error }))
..... }))
... }
> settle([ Promise.reject('help'), Promise.resolve('yesss') ]).then( settled => console.log(settled) )
Promise { <pending> }
> [ { state: 'rejected', error: 'help' },
{ state: 'fulfilled', result: 'yesss' } ] Notice no warning output. Let me know if this is what you are looking for. Thanks for your time! |
Sorry, was on a mobile so the reply was rather on the brief side. The behavior difference test is what I had in mind (the warnings are similar but not the same). I've now run the code and indeed - the last version that does not produce the warning is Going to check what happened between 3.6.0 and 3.6.1... |
Some more information about my environment: All output above was with [email protected] and [email protected]. macOS Sierra 10.12.1 |
|
It's right there in the middle of that commit - if I checkout
|
I have found the root cause - it's the creation of an extra Thenable that causes the warning to be printed. CC @briancavalier 'cause when.js Handler internals are at play here. The flow in the newest when.js version is as follows:
However, what about our first Thenable? It will be resolved (by rejecting) when the original foreign Promise rejects (because there is an
Whew, that was a tricky one. This bug has only shown up because the function Also note that the I'll try and come up with a clean fix for |
* Fix unhandled rejection warnings that resulted from creating superfluous Thenables during optimizations in settleOne() when working with foreign Promise objects
Got it. Pull request #494 |
@rooftopsparrow can you confirm that this issue is fixed for you on |
Looks great! > when.settle([ Promise.reject('help'), Promise.resolve('yesss') ])
{ state: 'pending' }
> p = _
{ state: 'fulfilled',
value:
[ { state: 'rejected', reason: 'help' },
{ state: 'fulfilled', value: 'yesss' } ] }
> when.settle([ when.reject('help'), when.resolve('yesss') ])
{ state: 'pending' }
> p = _
{ state: 'fulfilled',
value:
[ { state: 'rejected', reason: 'help' },
{ state: 'fulfilled', value: 'yesss' } ] } Output above is on node v6.9.1. macOS Sierra 10.12.1 and on commit facc6ba |
Hello!
I'm wondering if this is expected behavior?
Notice that we get a warning when using global Promises but we do not get that warning with when promises. It has caused some painful debugging to find that it wasn't actually unhandled.
Thanks for your time and library!
The text was updated successfully, but these errors were encountered: