Let's say I have 12 async/await functions, and on the 12th one deep, an error happens. Right now, I have this code to catch all errors:
process.on('unhandledRejection', function {
console.error(err);
process.exit(1);
});
The problem is, the stacktrace is not returned:
ReferenceError: sdfg is not defined
- get.js:29 Fruit.module.exports [as get]
/project/models/fruit/get.js:29:2
- next_tick.js:129 process._tickDomainCallback
internal/process/next_tick.js:129:7
On other projects, when I used callbacks with the structure of:
function doSomething(err, done) {
if (err) { return done(err); }
/* do something */
return done(null, true);
}
Then I had a nice stack trace of where the error has occured and the steps that led there. Now with async/await I've tried catching errors at all kinds of levels with no result. I've also tried longjohn and stackup -- and I still get only the last function that threw the error.
Help -- how do I see the complete stack?! And what's the proper way to catch nested async/await errors?
EDIT: (a complete example)
const getA = async () => {
await getB();
}
const getB = async () => {
await getC();
sdgf();
}
const getC = async () => {}
const start = async () => {
await getA();
}
start().then().catch(e => console.error(e));