diff --git a/lib/internal/modules/run_main.js b/lib/internal/modules/run_main.js index 507d076d162b0b..d7b0ee56a1e8a5 100644 --- a/lib/internal/modules/run_main.js +++ b/lib/internal/modules/run_main.js @@ -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