Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS: Is is possible to show the stack trace of a calling async function?

Most APIs in node libraries are asynchronous by design. When an exception is thrown in a callback the stacktrace shows only the call stack starting at process._tickCallback.

I wonder whether there is a trick to show also the stack trace of the function that trigerred the _tickCallback.

like image 732
earizon Avatar asked Oct 28 '16 08:10

earizon


2 Answers

In Node.js 12, Async Stack Traces come out of the box with flag

--async-stack-traces

Node.js Foundation release post - https://medium.com/@nodejs/introducing-node-js-12-76c41a1b3f3f

like image 200
ForgetfulFellow Avatar answered Sep 28 '22 09:09

ForgetfulFellow


In node 8 version appeared async_hooks

trace uses this for async stack traces

like image 31
darky Avatar answered Sep 28 '22 08:09

darky