Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find out where an unhandled promise rejection occured? [duplicate]

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.

How do I find the line of code where the unhandled rejection occurred?

like image 483
mikemaccana Avatar asked Jun 02 '17 12:06

mikemaccana


1 Answers

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

like image 162
ponury-kostek Avatar answered Nov 15 '22 08:11

ponury-kostek