-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
Source-mapping is working correctly for exceptions handled by a try/catch statement (or unhandled), but in the case of exceptions handled by a Promise.catch callback, it prints the undesirable trace:
Trace: [TypeError: undefined is not a function]
at promiseHandle (/Users/gabriluiz/Documents/opencontract/node_modules/traceur/bin/traceur.js:2359:20)
at /Users/gabriluiz/Documents/opencontract/node_modules/traceur/bin/traceur.js:2353:9
at flush (/Users/gabriluiz/Documents/opencontract/node_modules/traceur/bin/traceur.js:2127:7)
at process._tickCallback (node.js:419:13)
at Function.Module.runMain (module.js:499:11)
at startup (node.js:119:16)
at node.js:906:3
This is important because, when using traceur's async/await, asynchronously thrown exceptions must be handled by a .catch statement in the outermost async function invocation, like so:
function timeout(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
async function foo() {
await timeout(1000);
throw new Error('sorry'); // this will be thrown asynchronously because it follows an await
}
foo().catch(console.trace.bind(console));
This exception will not be caught by sync try/catch, nor by the node shell's regular error handler. (This is in contrast with the try { await foo(); } catch (e) { ... } idiom, which works well, except you can't use await in the script's top-level context (that is, outside of an async function.)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels