Skip to content

Commit

Permalink
fixup! fixup! module: handle Top-Level Await non-fulfills better
Browse files Browse the repository at this point in the history
  • Loading branch information
addaleax committed Aug 6, 2020
1 parent 5201960 commit 9b3aa51
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions lib/internal/modules/run_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,14 @@ function runMainESM(mainPath) {

function handleMainPromise(promise) {
// Handle a Promise from running code that potentially does Top-Level Await.
// In that case, it makes sense to:
// - Treat a rejection as an unhandled exception
// - Set the exit code to a specific non-zero value if the main code never
// finishes running.
// In that case, it makes sense to set the exit code to a specific non-zero
// value if the main code never finishes running.
function handler() {
if (process.exitCode === undefined)
process.exitCode = 13;
}
process.on('exit', handler);
promise
.finally(() => process.off('exit', handler))
.catch((err) => {
internalBinding('errors').triggerUncaughtException(
err, true /* fromPromise */);
});
return promise.finally(() => process.off('exit', handler));
}

// For backwards compatibility, we have to run a bunch of
Expand Down

0 comments on commit 9b3aa51

Please sign in to comment.