Skip to content

Instantly share code, notes, and snippets.

@public
Last active August 22, 2022 08:38
Show Gist options
  • Save public/bdab69f5b80bd2700829e6aac617346f to your computer and use it in GitHub Desktop.
Save public/bdab69f5b80bd2700829e6aac617346f to your computer and use it in GitHub Desktop.
async function awaitReturn() {
return await Promise.resolve('awaited this promise').then((x) => {
throw new Error(x);
});
}
async function noAwaitReturn() {
return Promise.resolve('did not await this promise').then((x) => {
throw new Error(x);
});
}
try {
await awaitReturn();
} catch (err) {
console.error(err);
}
try {
await noAwaitReturn();
} catch (err) {
console.error(err);
}
@public
Copy link
Author

public commented Aug 22, 2022

This code produces 2 different stack traces. You choose which one is more useful.

Error: awaited this promise
    at file:///Users/alexs/code/purple-dot/return-await.mjs:3:11
    at async awaitReturn (file:///Users/alexs/code/purple-dot/return-await.mjs:2:10)
    at async file:///Users/alexs/code/purple-dot/return-await.mjs:14:3

Error: did not await this promise
    at file:///Users/alexs/code/purple-dot/return-await.mjs:9:11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment