There should be a way to generate warnings when reject is called after resolve
See original GitHub issueI have lost many hours investigating a problem that arrived due to a promise being resolved and rejected afterward. Here is an example to illustrate the problem I had:
var Promise = require('bluebird')
new Promise(function (resolve, reject) {
console.log('resolving')
resolve()
setTimeout(function () {
console.log('rejecting')
reject(new Error())
}, 0)
}).then(function () {
console.log('resolved')
}).catch(function (err) {
console.log('rejected', err)
})
I tried to activate warnings but I din’t get any:
root@874aba35616a:/tmp# BLUEBIRD_WARNINGS=1 node example.js
resolving
rejecting
resolved
root@874aba35616a:/tmp#
When I don’t supply an error to reject, I get a warning so I’m confident that the warning mechanism gets activated using the environment variable.
Is there a way to have these warnings? If not can you add this feature? I bet it would save a lot of debugging time.
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Promise reject() causes "Uncaught (in promise)" warning
To fix this, make sure that your error code (called by the reject function) does not throw an exception. It should simply return....
Read more >Error handling with promises - The Modern JavaScript Tutorial
Here's an example: new Promise((resolve, reject) => { resolve("ok"); }). then((result) => { throw new Error("Whoops!"); // rejects the promise ...
Read more >Promise.resolve() - JavaScript - MDN Web Docs
The Promise.resolve() method "resolves" a given value to a Promise. If the value is a promise, that promise is returned; if the value...
Read more >Applying a timeout to your promises
Quick tutorial on how to create a generic timeout function that can be applied to any previous existing promise.
Read more >Promises Cheatsheet - Intermediate JavaScript - Codecademy
Afterwards, it transitions to one of the two states: resolved or rejected . ... The .then() method of a JavaScript Promise object can...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Here is the code I was debugging:
The bug was in
self.processSomeRows
that returned too quickly for the last chunk. That resolved the promise but the previous chunk was generating an error later on. This error was totally invisible.I actually use this fact as a feature (resolving after rejecting)