Search code examples
javascriptnode.jsdebuggingpromisevisual-studio-code

How to get "initiator" debugging information for promises?


When debugging a then promise callback in Node.JS using something like Visual Studio Code, the Call Stack seems almost redundant. Instead of providing the function that actually called my code from a logical perspective it provides the function that called my code from a literal perspective; the Bluebird library (or maybe Q library) functions. What I actually want to see is the previous promise function that was executed, or the "initiator" of the promise chain. From a logical perspective that is the program flow I care about. Is there a way I can get this information during debugging?


Solution

  • Just so you realize, what you're asking for isn't the actual call stack. Per promise specification, the call stack is clear of all your code when a .then() handler is called - that's what happens with asynchronous handlers.

    That said, I understand what you would like to see (an async flow stack or something like that), but I'm not aware of any tool that will provide that as of 2017. The Bluebird promise library has a means of giving you long stack traces which might be relevant to your problem