gpt4 book ai didi

javascript - Bluebird 忘记返回警告丢失

转载 作者:数据小太阳 更新时间:2023-10-29 06:04:08 28 4
gpt4 key购买 nike

我期待 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com