我如何找出未处理的承诺被拒绝的地方? [英] How do I find out where an unhandled promise rejection occured?

查看:98
本文介绍了我如何找出未处理的承诺被拒绝的地方?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

快速序言:我了解承诺,我了解解决和拒绝.这不是问题.

Quick preface: I understand Promises, I understand resolving and rejection. This is not the question.

(node:14104) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: "callback" argument must be a function
(node:14104) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.\

我知道在代码的某个地方没有回调"参数,该参数应该是一个函数.这也不是我的问题.

I understand somewhere in my code a 'callback' argument, which should be a function, isn't. That is also not my question.

如何找到发生未处理的拒绝的代码行?

推荐答案

节点的'unhandledRejection'事件应该可以解决您的奥秘:

node's 'unhandledRejection' event should solve your mystery:

process.on('unhandledRejection', (reason, promise) => {
    console.warn('Unhandled promise rejection:', promise, 'reason:', reason.stack || reason);
});

https://repl.it/I3JJ/2

这篇关于我如何找出未处理的承诺被拒绝的地方?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆