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.

Feature Request: Alternate way to suppress warnings

See original GitHub issue
  1. What version of bluebird is the issue happening on? 3.3.4
  2. What platform and version? Node v5.9.1
  3. 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:open
  • Created 7 years ago
  • Reactions:1
  • Comments:20 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
ben-pagecommented, Oct 26, 2016

@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 the IS_FINAL flag on the promise created and returned by .done(), the Promise .done() was called on.

1reaction
ben-pagecommented, Oct 26, 2016

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.

function fakeWork() {
    return new Promise(resolve => {
        resolve();
    });
}

//module 1
function doSomething1() {
    const p = fakeWork()
    p.suppressRunawayWarning(); //proposed way to suppress the warning as the producer
    p.then(() => {
        console.log('did thing');
    })
    .catch(err => {
        //totally handle error
    }); 
}

//module 2
function doSomething2() {
    return fakeWork()
        .then(() => {
            doSomething1(); //calling another module, but not aware that it uses Bluebird internally

            //return null; //user of module is required to understand it's internals and suppress warning
        });
}

doSomething2()
    .then(() => {
        console.log('did something 2');
    });
Read more comments on GitHub >

github_iconTop Results From Across the Web

[feature request] Ability to disable warnings locally #9430
We currently have the "notation-overridden" warning disabled globally in Iris. I'd like to enable it again, but we have some cases where ...
Read more >
4.8. Options to Request or Suppress Warnings
Warn whenever a statement computes a result that is explicitly not used. To suppress this warning cast the expression to void. All the...
Read more >
Options to Request or Suppress Warnings
You can request many specific warnings with options beginning with '-W'; for instance, use '-Wimplicit' to request warnings on implicit declarations.
Read more >
How to disable Python warnings? - Stack Overflow
Look at the Temporarily Suppressing Warnings section of the Python docs: If you are using code that you know will raise a warning,...
Read more >
Suppress code analysis warnings - .NET - Microsoft Learn
You can disable a rule that's causing a warning by setting its severity to none in an EditorConfig or AnalyzerConfig configuration file. This ......
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