-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
async/await Warning: a promise was created in a handler but was not returned from it #903
Comments
@sahat which version of babel are you using? |
Node 4.2.1
|
I was able to suppress the warning by adding this at the beginning of my file: Promise.config({
warnings: false
}); But the strange thing is, I thought warnings are OFF by default according to the docs? Promise.config(Object {
warnings: boolean=false,
longStackTraces: boolean=false,
cancellation: boolean=false
} options) -> undefined; |
@sahat babel6 has some issues with async functions at the moment, I would check whether you can replicate the issue using something like this without compiling: var fs = require('fs-extra');
var path = require('path');
var Promise = require('bluebird');
var mkdirs = Promise.promisify(fs.mkdirs);
var copy = Promise.promisify(fs.copy);
var generateExpress = Promise.coroutine(function *generateExpress(params) {
var build = path.join(__dirname, 'build', params.uuid);
var express = path.join(__dirname, 'modules', 'express');
yield copy(express, build);
yield mkdirs(path.join(build, 'public', 'images'));
yield mkdirs(path.join(build, 'public', 'javascripts'));
yield mkdirs(path.join(build, 'public', 'stylesheets'));
}); |
FWIW, I'm seeing a very similar issue using This code prints the same warning, but only twice. It does NOT print the warning when using
var Promise = require('bluebird');
var co = require('co');
function getPromise(val, err) {
return new Promise(function (resolve, reject) {
if (err) {
reject(err);
} else {
resolve(val);
}
});
}
var generator = function *() {
var a = yield getPromise(1);
var b = yield getPromise(2);
var c = yield getPromise(3);
console.log(a, b, c);
};
// warnings
co(generator);
// ok
Promise.coroutine(generator)(); bluebird: 3.0.6 |
I was going to create another issue for this, but I'm just going to add a comment here. Some combination of jaredhanson/passport, jaredhanson/oauth2orize, bluebird (3.0.6) and our code is causing this warning to be raised any time the code paths through some of our functions. As far as I can see, none of those functions create promises that aren't returned. The only common factor I can see is that the final function before the warning always has a I'm not sure what else I can do other than disabling the warnings, as the logs aren't telling me enough to figure out why Bluebird thinks there's a promise created that wasn't returned. As I led with, I suspect it has something to do with the libraries I'm using in concert with the rest of the code; but, I'm not sure about that. Is there any way to get more information than the warning currently shows? Also, there's a double space in the text of the warning that makes me think there's something that's supposed to be concatenated there, but isn't:
EDIT: If you think this is sufficiently unrelated, I'll create a separate issue for it. I was just concerned that I am basically giving you no information (because I don't have any, really); so, I didn't want to make a full issue, given that. |
The problem is that you cannot detect whether the immediate handler created the promise or some function the handler calls. A handler might call into 30 levels of functions where function 28 creates a promise, then if the handler doesn't have a |
Right. I can appreciate the limitations that Bluebird is bound by. So, the question becomes: understanding that most code bases will interact with (for many intentions) opaque modules, with the advent of these warnings, what is the expected use pattern? In my case, I have verified that none of my code is written improperly; so, moving forward, either we: (1) leave the warnings enabled, and they will be disabled when |
Hm, I guess this could be fixed by the |
@phpnode Has this been filed with the Babel team? I can't seem to find anything about it there. They need to be made aware that their async generator code generates Promises incorrectly. |
@globexdesigns there are a lot of issues with async functions in babel6 but they're slowly getting fixed, here's just a few for example: https://phabricator.babeljs.io/T2765 |
I have experimented with a design that allows knowing if the handler was immediately creating a promise but not returning it. However, this has tremendous performance cost and it is trading off false positives for false negative. Additionally, false positives can always be dealth with by returning null while false negatives cannot be dealt with at all. Example of false negative: function returnsPromise() {
return Promise.resolve();
}
somePromise.then(function() {
// Forgot to return but no warning
// because the promise is not immediately created here.
returnsPromise();
}); |
@zhm Out of curiosity, have you filled an issue with babel regarding your issue at #903 (comment) ? I'm also getting some weird interoperability issues between co (and generators) and bluebird. |
I've discovered this issue happening allot when Bluebird using async code + loops are processed with regenerator resulting in a certain format of I reported this on the babel bug tracker: |
Here is my
async
function that does not return anything:It throws a bunch of warnings "a promise was created in a handler but was not returned from it". Previously, before switching to async/await, to get around this issue, I would add a
return
in front of every promise.Is this a bug or working as intended by bluebird library?
The text was updated successfully, but these errors were encountered: