Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding source of unhandled promise rejection: TypeError: Chaining cycle detected for promise

I'm trying to find the source of an unhandled rejection from a Promise in Node.js

I've tried upgrading to Node version 12, using the --async-stack-traces option, and listening for them using:

process.on("unhandledRejection",( reason, promise ) => {
  console.log(reason);
  console.log(promise);
});

But I still don't see any helpful stack trace to help me find the culprit!

UnhandledPromiseRejectionWarning: TypeError: Chaining cycle detected for promise #<Promise>
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:89675) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 11)

Running Node v10.10.0

like image 964
d-_-b Avatar asked Dec 11 '19 13:12

d-_-b


1 Answers

If you miss an helpful stacktrace, you can make node create a new one by re-throwing your error in your handler like this:

process.on('unhandledRejection', (reason, p) => { throw reason });

This way, you should be able to track down the culprit.

like image 200
Gomino Avatar answered Sep 21 '22 14:09

Gomino