Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fixup! fixup! module: handle Top-Level Await non-fulfills better
  • Loading branch information
addaleax committed Aug 6, 2020
commit 9b3aa518d030736c9b7528f24e8ce8cf86512647
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