From 8a4a4c63699c50e11b9ba72876f6ffd46ba9714a Mon Sep 17 00:00:00 2001 From: Julien Gilli Date: Tue, 26 Feb 2019 12:01:03 -0800 Subject: [PATCH] domain: allow concurrent user-land impl Currently, only one domain-lke implementation (the core domain one) can be used to handle uncaught exceptions or unhandled error events. This PR aims at making it possible for different domain-like user-land implementations to be used concurrently (including with the core domain impl) so that the state of the core domain module (doc deprecated) does not prevent users of domains from having a well-maintained domain-like facility. Ref: https://github.com/nodejs/node/issues/23348 --- doc/api/errors.md | 17 ---- doc/api/repl.md | 9 +- lib/domain.js | 87 +++---------------- lib/events.js | 58 ++++++++++--- lib/internal/errors.js | 9 -- ...ad-after-set-uncaught-exception-capture.js | 10 --- ...t-uncaught-exception-capture-after-load.js | 28 ------ 7 files changed, 59 insertions(+), 159 deletions(-) delete mode 100644 test/parallel/test-domain-set-uncaught-exception-capture-after-load.js diff --git a/doc/api/errors.md b/doc/api/errors.md index b9d26421497fde..b00976e74f1050 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -818,23 +818,6 @@ A signing `key` was not provided to the [`sign.sign()`][] method. `c-ares` failed to set the DNS server. - -### ERR_DOMAIN_CALLBACK_NOT_AVAILABLE - -The `domain` module was not usable since it could not establish the required -error handling hooks, because -[`process.setUncaughtExceptionCaptureCallback()`][] had been called at an -earlier point in time. - - -### ERR_DOMAIN_CANNOT_SET_UNCAUGHT_EXCEPTION_CAPTURE - -[`process.setUncaughtExceptionCaptureCallback()`][] could not be called -because the `domain` module has been loaded at an earlier point in time. - -The stack trace is extended to include the point in time at which the -`domain` module had been loaded. - ### ERR_ENCODING_INVALID_ENCODED_DATA diff --git a/doc/api/repl.md b/doc/api/repl.md index 324b15f3852288..703286843ad86a 100644 --- a/doc/api/repl.md +++ b/doc/api/repl.md @@ -142,11 +142,8 @@ global or scoped variable, the input `fs` will be evaluated on-demand as The REPL uses the [`domain`][] module to catch all uncaught exceptions for that REPL session. -This use of the [`domain`][] module in the REPL has these side effects: - -* Uncaught exceptions do not emit the [`'uncaughtException'`][] event. -* Trying to use [`process.setUncaughtExceptionCaptureCallback()`][] throws - an [`ERR_DOMAIN_CANNOT_SET_UNCAUGHT_EXCEPTION_CAPTURE`][] error. +This use of the [`domain`][] module in the REPL has the side effect of making +uncaught exceptions not emit the [`'uncaughtException'`][] event. #### Assignment of the `_` (underscore) variable