简体   繁体   English

什么是“误报”拒绝承诺? possiblyUnhandledRejection?

[英]What is a “false positive” rejected promise? possiblyUnhandledRejection?

Im using the Bluebird promise library in node. 我在节点中使用了Bluebird Promise库。

I have a section in my code that catches a rejected promise and does not re-throw it. 我的代码中有一段捕获了被拒绝的诺言,并且没有将其重新抛出。

"unhandledRejection" is still triggered with that same promise afterwards - why is this when it has already been handled? 之后,“ unhandledRejection”仍会以相同的承诺触发-为什么已经处理了它,为什么会这样?

What is a "possiblyUnhandledRejection"? 什么是“可能未处理的拒绝”?

http://bluebirdjs.com/docs/api/error-management-configuration.html http://bluebirdjs.com/docs/api/error-management-configuration.html

However because it is possible to handle a rejected promise at any time in the indeterminate future, some programming patterns will result in false positives . 但是,由于可以在不确定的将来随时处理被拒绝的承诺,因此某些编程模式将导致误报 Because such programming patterns are not necessary and can always be refactored to never cause false positives , we recommend doing that to keep debugging as easy as possible. 由于此类编程模式不是必需的,并且可以始终进行重构以永远不会导致误报 ,因此我们建议您这样做,以使调试尽可能容易。

What are the "programming patterns" mentioned here? 这里提到的“编程模式”是什么?

Is this related to this pattern (one rejected promise is chained twice or more and one of them does not catch): https://github.com/petkaantonov/bluebird/issues/695#issuecomment-155373565 这与这种模式有关吗(一个被拒绝的诺言被链接了两次或更多次,其中一个没有被抓住): https : //github.com/petkaantonov/bluebird/issues/695#issuecomment-155373565

Thanks 谢谢

The mentioned programming practices involve installing the error handler only after the error already occurred. 提到的编程实践涉及仅在错误已经发生之后才安装错误处理程序。 For an example, take 举个例子

var a = Promise.delay(Math.random()*1000)
        .then(function(){ throw new Error(); });
var b = Promise.delay(Math.random()*1000)
        .then(function() { return a; })
        .catch(function() { console.log("It's ok."); });

In about half the cases, a 's delay is shorter than b 's, and we'll get an unhandledRejection warning. 在大约一半的情况下, a的延迟比b的延迟短,我们将收到unhandledRejection警告。

Is this related to the pattern where one rejected promise is chained twice or more and one of them does not catch? 这与一个被拒绝的承诺被链接两次或多次而其中一个没有被抓住的模式有关吗?

No, that's simply a bug. 不,那只是一个错误。 All branches need to have an error handler. 所有分支都需要具有错误处理程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM