petkaantonov/bluebird

At Promise fromNode fromCallback - a promise was created but was not returned from it

mercteil opened this issue · 6 comments

(This issue tracker is only for bug reports or feature requests, if this is neither, please choose appropriate channel from http://bluebirdjs.com/docs/support.html)

Please answer the questions the best you can:

  1. What version of bluebird is the issue happening on?
  • 3.7.2
  1. What platform and version? (For example Node.js 0.12 or Google Chrome 32)
  • Node 12, Heroku worker
  • Using babel 7
  1. Did this issue happen with earlier version of bluebird?
    Locally there is no issue at all. I haven't known about this until I pushed to Heroku.

I am having this issue on Heroku:

2020-02-19T12:37:49.314100+00:00 app[worker.1]: (node:4) Warning: a promise was created in a handler at internal/process/task_queues.js:79:21 but was not returned from it, see http://goo.gl/rRqMUw
2020-02-19T12:37:49.314102+00:00 app[worker.1]:     at Function.Promise.fromNode.Promise.fromCallback (/app/node_modules/bluebird/js/release/promise.js:206:9)

Since it is pointing to the bluebird node_module directly I assume there might be an issue in the package. (Btw. in the lib at the pointed fromNode.fromCallback there is this weird indentation of a ternary).

image

You have a promise somewhere you create in a .then but forgot to return. Turn on long stack traces and figure it out :]

In general, please open support requests according to http://bluebirdjs.com/docs/support.html

See also: https://github.com/petkaantonov/bluebird/blob/808fdf8fce0cf4dbb1b95129607777a0cd53df36/docs/docs/warning-explanations.md#warning-a-promise-was-created-in-a-handler-but-was-not-returned-from-it

I was just bitten by this, too. Basically, in BlueBird you're never allowed to have a Promise chain that ends in undefined. A little annoying if you actually want to return undefined from a Promise, but there we are. The documentation seems to suggest that you need to actually create a promise inside a handler for the warning to appear, but this does not appear to always be the case.

The documentation seems to suggest that you need to actually create a promise inside a handler for the warning to appear, but this does not appear to always be the case.

The test is literally that - if you don't create a promise inside and not return it creating a broken chain - no warning.

Based on reading the source, I would agree with you... Except that in this example the then block clearly creates no promises, but when I removed the return null at the end of it someone immediately raised an issue because they started seeing this warning:

https://github.com/jwalton/node-amqp-connection-manager/blob/5038376ade39f2696a85552db786494d42ea98a2/src/AmqpConnectionManager.ts#L346-L380

Oh... I bet I know why. I bet the person who raised the issue was creating a Bluebird promise inside the connect handler, which would be run synchronously from inside this block. Sneaky.

I suppose if you really wanted to create a Promise<void>, you could return Promise.resolve() (or return Promise.resolve(undefined)).