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.

Confusing warning: a promise was created in a handler but was not returned from it

See original GitHub issue
  1. What version of bluebird is the issue happening on? - 3.4.7
  2. What platform and version? – Chrome, Firefox, Safari (require('bluebird') + browserify)
  3. Did this issue happen with earlier version of bluebird? - no, 2.9*

Should not .done() to suppress the warning?

// some button.js
function onClick() {
    this.loadOptions()
        .then((options) => {
            // some external event interface
            this.trigger('loaded', options); // sync
        })
        .done();
}

// some external button listener like table.js
button.on('loaded', (e, options) => {
    this.loadSomeData(options)
        .then((data) => {
            this.updateSelf(data); // sync
        })
            .done();
});

We have warning bacause promise from loadSomeData() created in a handler of promise from loadOptions()

Also I think this warning works strange, two examples:

function test1() {
    Bluebird
        .resolve()
        .done(() => {
            Bluebird.resolve().done();
        });
}

no warning above

function test2() {
    Bluebird
        .resolve()
        .then(() => {
            Bluebird.resolve().done();
        })
        .done();
}

warning happened

Guess the examples are equal, but warning happening

I think that in both cases, the warning shouldn’t be happen, because it is not possible to return promise in any case.

PS: all the examples are full synthetic but reflecting real cases

PPS: http://bluebirdjs.com/docs/api/promise.config.html#promise.config it says that all the options are false by default, but I get the warnings while not explicitly set {warnings: false}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

11reactions
akhourycommented, Dec 31, 2017

bluebird was getting loaded by other third party libraries, so this didn’t work for me, not sure why, maybe the other libs are overriding this config at some point.

require('bluebird').config({
  warnings: {
    wForgottenReturn: false
  }
});

However, this did

process.env.BLUEBIRD_W_FORGOTTEN_RETURN = 0;

source: http://bluebirdjs.com/docs/api/promise.config.html

2reactions
adamreisnzcommented, Oct 8, 2017

If you know what you’re doing and don’t want to silence all warnings, you can create runaway promises without causing this warning by returning null

I did pick up on that, but that’s hardly a solution either as it requires me to refactor a lot of my code, and doesn’t solve the issue with warnings originating from 3rd party libraries.

In the end I found this to disable these pesky warnings:

Promise.config({
    // Enables all warnings except forgotten return statements.
    warnings: {
        wForgottenReturn: false
    }
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Why do I not get the warning "a promise was created in a ...
I observed some cases where I'm getting following warning: Warning: a promise was created in a handler but was not returned from it....
Read more >
Changelog - Bluebird JS
The "a promise was created in a handler but not returned from it" warning now highlights the file, line and column where the...
Read more >
Warning: A Promise Was Created In A Handler At But Was Not ...
Bluebird warning A promise was created in a handler but was not returned from it. Solution: First try and update all your dependencies....
Read more >
warning: a promise was created in a handler but was not returned ...
Bluebird is a fully featured JavaScript promises library with unmatched performance. bluebird npm. This is a playground to test code. It runs a...
Read more >
Process | Node.js v19.3.0 Documentation
The 'unhandledRejection' event is emitted whenever a Promise is rejected and no error handler is attached to the promise within a turn of...
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