Skip to content

Instantly share code, notes, and snippets.

@mserranom
Last active August 1, 2019 09:53
Show Gist options
  • Save mserranom/6da8df1c6af93d22e20a4011a861c848 to your computer and use it in GitHub Desktop.
Save mserranom/6da8df1c6af93d22e20a4011a861c848 to your computer and use it in GitHub Desktop.
Async stack traces with Node 12
async function functionOne() {
await new Promise((resolve) => {
setTimeout(() => { resolve(); }, 1000);
});
throw new Error('Error here prints stack');
}
async function functionTwo() {
await functionOne();
}
async function functionThree() {
await functionTwo();
}
functionThree()
.catch((error) => {
console.error(error);
});
// $ nvm use 10.16.0 && node node_12_async_stack_trace.js
// Now using node v10.16.0 (npm v6.9.0)
// Error: Error here prints stack
// at functionOne (./node_12_async_stack_trace.js:5:11)
// $ nvm use 12.6.0 && node node_12_async_stack_trace.js
// Now using node v10.6.0 (npm v6.9.0)
// Error: Error here prints stack
// at functionOne (./node_12_async_stack_trace.js:5:11)
// at async functionTwo (./node_12_async_stack_trace.js:9:5)
// at async functionThree (./node_12_async_stack_trace.js:13:5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment