javascript - Bluebird 忘记返回警告丢失

标签 javascript node.js bluebird

我期待 Bluebird forgotten return warning出现,但由于某种原因它不起作用。

A demo :

const Bluebird = require('bluebird');

Bluebird.config({
    warnings: true
})

Bluebird.resolve(1)
.then(() => {
    Bluebird.resolve(2); // should warn about forgotten return
})
.then(two => console.log(two));

如何解决输出警告?

我怀疑我以前遇到过这个问题,但我不记得解决方案是什么。

最佳答案

似乎需要启用长堆栈跟踪才能显示警告。您可以使用配置对象来启用它们 ( docs ) ( demo ):

Bluebird.config({
    warnings: true,
    longStackTraces: true
});

或环境变量 ( docs ) ( demo ):

In Node.js you may configure warnings and long stack traces for the entire process using environment variables:

BLUEBIRD_LONG_STACK_TRACES=1 BLUEBIRD_WARNINGS=1 node app.js

Both features are automatically enabled if the BLUEBIRD_DEBUG environment variable has been set or if the NODE_ENV environment variable is equal to "development".

To enable long stack traces and warnings in node development:

$ NODE_ENV=development node server.js

To enable long stack traces and warnings in node production:

$ BLUEBIRD_DEBUG=1 node server.js

See Environment Variables.


编辑为什么这是必要的:

似乎默认情况下警告和长堆栈跟踪都是禁用的,并且仅在检测到开发环境时才启用,请参阅 here :

Note that even though false is the default here, a development environment might be detected which automatically enables long stack traces and warnings.

要在生产环境中显示警告,您不仅必须启用警告,还必须启用长堆栈跟踪,请参阅 herehere .

关于javascript - Bluebird 忘记返回警告丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54266477/

相关文章:

javascript - 如何在 FabricJS 上复制/粘贴后保持 IText 可编辑?

javascript - 使用 ExtJs 自动完成文本字段

javascript - 从字符串中提取图像标签

javascript - 单击按钮时加载 jqGrid 但第二次失败

javascript - 删除连线后两个 Node 保持链接

javascript - Bluebird promisifyAll 未创建整套异步函数

javascript - JS : Text to Image

javascript - 如何在循环中对一堆查询进行排序?

javascript - Bluebird Promise.all 在 Promise 链中间捕获并继续 Promise

javascript - 如何处理来自多个 then in catch of javascript promises 的错误?