My application has many modules and uses promises all over the place.
On occasion, deep in one of these modules, my code throws an exception and the promise chain gets rejected. If this error was reproducible, I could single step until I found the exception. But it's not.
How do I get nodejs to generate a traceback to identify the guilty module, function and line of code?
Here is a trivial example.
'use strict';
// pretend multiple modules, each with deep complicated chains of Promises
Promise.resolve()
.then(() => { return Promise.resolve() })
.then(() => { return Promise.resolve() })
.then(() => { return Promise.resolve() })
.then(() => {
x = "find me if you can, x is very common variable name";
return Promise.resolve
})
.then(() => { return Promise.resolve() })
.then(() => { return Promise.resolve() })
.catch((e) => { console.log("where did you come from " + e) })
The output from the above is "where did you come from ReferenceError: x is not defined"