From df5db768f8c71ab4c533f558c6ad81ab556320a8 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Mon, 27 Dec 2021 16:05:35 +0100 Subject: [PATCH] doc: clarify `uncaughtException` `origin` for ESM Fixes: https://github.com/nodejs/node/issues/41328 --- doc/api/process.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/doc/api/process.md b/doc/api/process.md index 1af45fe0240830..5558842729a221 100644 --- a/doc/api/process.md +++ b/doc/api/process.md @@ -337,7 +337,7 @@ changes: rejection or from an synchronous error. Can either be `'uncaughtException'` or `'unhandledRejection'`. The latter is only used in conjunction with the [`--unhandled-rejections`][] flag set to `strict` or `throw` and - an unhandled rejection. + an unhandled rejection, or when the entry point is an ES module. The `'uncaughtException'` event is emitted when an uncaught JavaScript exception bubbles all the way back to the event loop. By default, Node.js @@ -365,6 +365,8 @@ setTimeout(() => { }, 500); // Intentionally cause an exception, but don't catch it. +// Because the exception happens when evaluating an ES module, this is +// undistinguishable from a Promise rejection, and will be reported as such. nonexistentFunc(); console.log('This will not run.'); ``` @@ -433,7 +435,7 @@ added: rejection or from synchronous errors. Can either be `'uncaughtException'` or `'unhandledRejection'`. The latter is only used in conjunction with the [`--unhandled-rejections`][] flag set to `strict` or `throw` and - an unhandled rejection. + an unhandled rejection, or when the entry point is an ES module. The `'uncaughtExceptionMonitor'` event is emitted before an `'uncaughtException'` event is emitted or a hook installed via @@ -451,6 +453,8 @@ process.on('uncaughtExceptionMonitor', (err, origin) => { }); // Intentionally cause an exception, but don't catch it. +// Because the exception happens when evaluating an ES module, this is +// undistinguishable from a Promise rejection, and will be reported as such. nonexistentFunc(); // Still crashes Node.js ``` @@ -503,7 +507,7 @@ process.on('unhandledRejection', (reason, promise) => { somePromise.then((res) => { return reportToUser(JSON.pasre(res)); // Note the typo (`pasre`) -}); // No `.catch()` or `.then()` +}); // No `.catch()` or `.then()` or `await`. ``` ```cjs @@ -531,7 +535,7 @@ function SomeResource() { } const resource = new SomeResource(); -// no .catch or .then on resource.loaded for at least a turn +// no await, .catch, or .then on resource.loaded for at least a turn ``` ```cjs