Feature Request: Alternate way to suppress warnings
See original GitHub issue- What version of bluebird is the issue happening on? 3.3.4
- What platform and version? Node v5.9.1
- Did this issue happen with earlier version of bluebird? Yes
Library authors can’t suppress the warning for runaway promises that they create, because it’s not the runaway Promise that needs to resolve to null, but the outer promise. Consider the following example:
'use strict';
var Promise = require('bluebird');
Promise.config({warnings: true, longStackTraces: true});
function otherLibrary() {
Promise.resolve()
.catch(function() {
//totally recover from error
})
.then(function () {
return null; //try to tell Bluebird we don't need the warning
});
}
Promise.resolve()
.then(function () {
otherLibrary();
})
.delay(500); //on Windows node doesn't flush the console stream before exiting
This triggers a runaway promise warning even though, otherLibrary
is trying to indicate that it wants to suppress the warning. So consumers of the library have to be aware of this and suppress the warning at every call, if they use promises as well.
Promise.resolve()
.then(function () {
otherLibrary();
return null; //this will suppress the warning
})
.delay(500); //on Windows node doesn't flush the console stream before exiting
I realize that the warning is thrown when the runaway promise is created, not when it’s resolved. So the otherLibrary
returning null is irrelevant. But, it would be nice to have a way to suppress the warning when creating the runaway promise.
Maybe a simple call that suppresses the warning for the next promise created.
function otherLibrary() {
Promise.suppressRunawayWarning();
Promise.resolve()
.catch(function() {
//totally recover from error
});
}
Or maybe it would be better to explicitly start a new promise chain.
function otherLibrary() {
Promise
.newChain()
.resolve()
.catch(function () {
//totally recover from error
});
}
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:20 (10 by maintainers)
@spion,
.done()
does not solve this case, the warning is still raised even if done is call on the Promise. I think this is because.done()
sets theIS_FINAL
flag on the promise created and returned by.done()
, the Promise.done()
was called on.So the last few messages are off topic. This issue is about providing a way for the author of method for flagging their promises as handled. Rather than requiring the users of the method to suppress warnings with
return null
. Currently, a runaway promise warning can be triggered when code that uses Bluebird consumes modules that also uses Bluebird. And the module author has no control over that.