From 7082a2775646c47ed18300c4921adf29983561dd Mon Sep 17 00:00:00 2001 From: Julien Gilli Date: Fri, 12 Oct 2018 10:18:22 -0700 Subject: [PATCH] process: allow multiple uncaught exception capture calbacks --- doc/api/cli.md | 2 +- doc/api/errors.md | 27 ------------------ doc/api/process.md | 13 +++------ doc/api/repl.md | 9 ++---- lib/domain.js | 28 ++++--------------- lib/internal/bootstrap/node.js | 8 ++++-- lib/internal/errors.js | 13 --------- lib/internal/process/main_thread_only.js | 2 ++ lib/internal/process/per_thread.js | 16 ++++++----- lib/repl.js | 12 ++++++++ ...ad-after-set-uncaught-exception-capture.js | 14 ++-------- ...t-uncaught-exception-capture-after-load.js | 28 ------------------- .../test-process-exception-capture-errors.js | 12 ++++---- ...ld-abort-on-uncaught-setflagsfromstring.js | 4 ++- ...eption-capture-should-abort-on-uncaught.js | 4 ++- .../test-process-exception-capture.js | 4 ++- 16 files changed, 57 insertions(+), 139 deletions(-) delete mode 100644 test/parallel/test-domain-set-uncaught-exception-capture-after-load.js diff --git a/doc/api/cli.md b/doc/api/cli.md index 29f3360dda1d78..90424d74f2c400 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -754,7 +754,7 @@ greater than `4` (its current default value). For more information, see the [`--openssl-config`]: #cli_openssl_config_file [`Buffer`]: buffer.html#buffer_class_buffer [`SlowBuffer`]: buffer.html#buffer_class_slowbuffer -[`process.setUncaughtExceptionCaptureCallback()`]: process.html#process_process_setuncaughtexceptioncapturecallback_fn +[`process.setUncaughtExceptionCaptureCallback()`]: process.html#process_process_setuncaughtexceptioncapturecallback_owner_fn [Chrome DevTools Protocol]: https://chromedevtools.github.io/devtools-protocol/ [REPL]: repl.html [ScriptCoverage]: https://chromedevtools.github.io/devtools-protocol/tot/Profiler#type-ScriptCoverage diff --git a/doc/api/errors.md b/doc/api/errors.md index 82c4e790e6b84b..9f8e8cf6c1f0fd 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -803,23 +803,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 @@ -1720,15 +1703,6 @@ A `Transform` stream finished with data still in the write buffer. The initialization of a TTY failed due to a system error. - -### ERR_UNCAUGHT_EXCEPTION_CAPTURE_ALREADY_SET - -[`process.setUncaughtExceptionCaptureCallback()`][] was called twice, -without first resetting the callback to `null`. - -This error is designed to prevent accidentally overwriting a callback registered -from another module. - ### ERR_UNESCAPED_CHARACTERS @@ -2153,7 +2127,6 @@ such as `process.stdout.on('data')`. [`new URL(input)`]: url.html#url_constructor_new_url_input_base [`new URLSearchParams(iterable)`]: url.html#url_constructor_new_urlsearchparams_iterable [`process.send()`]: process.html#process_process_send_message_sendhandle_options_callback -[`process.setUncaughtExceptionCaptureCallback()`]: process.html#process_process_setuncaughtexceptioncapturecallback_fn [`readable._read()`]: stream.html#stream_readable_read_size_1 [`require('crypto').setEngine()`]: crypto.html#crypto_crypto_setengine_engine_flags [`require()`]: modules.html#modules_require diff --git a/doc/api/process.md b/doc/api/process.md index 3907271bbfa26c..c24df1fd892dfc 100644 --- a/doc/api/process.md +++ b/doc/api/process.md @@ -1807,11 +1807,12 @@ This function is only available on POSIX platforms (i.e. not Windows or Android). This feature is not available in [`Worker`][] threads. -## process.setUncaughtExceptionCaptureCallback(fn) +## process.setUncaughtExceptionCaptureCallback(owner, fn) +* `owner` {symbol} * `fn` {Function|null} The `process.setUncaughtExceptionCaptureCallback()` function sets a function @@ -1824,12 +1825,7 @@ command line or set through [`v8.setFlagsFromString()`][], the process will not abort. To unset the capture function, -`process.setUncaughtExceptionCaptureCallback(null)` may be used. Calling this -method with a non-`null` argument while another capture function is set will -throw an error. - -Using this function is mutually exclusive with using the deprecated -[`domain`][] built-in module. +`process.setUncaughtExceptionCaptureCallback(owner, null)` may be used. ## process.stderr @@ -2137,7 +2133,6 @@ cases: [`Worker`]: worker_threads.html#worker_threads_class_worker [`console.error()`]: console.html#console_console_error_data_args [`console.log()`]: console.html#console_console_log_data_args -[`domain`]: domain.html [`net.Server`]: net.html#net_class_net_server [`net.Socket`]: net.html#net_class_net_socket [`NODE_OPTIONS`]: cli.html#cli_node_options_options @@ -2150,7 +2145,7 @@ cases: [`process.hrtime()`]: #process_process_hrtime_time [`process.hrtime.bigint()`]: #process_process_hrtime_bigint [`process.kill()`]: #process_process_kill_pid_signal -[`process.setUncaughtExceptionCaptureCallback()`]: process.html#process_process_setuncaughtexceptioncapturecallback_fn +[`process.setUncaughtExceptionCaptureCallback()`]: process.html#process_process_setuncaughtexceptioncapturecallback_owner_fn [`promise.catch()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch [`require()`]: globals.html#globals_require [`require.main`]: modules.html#modules_accessing_the_main_module diff --git a/doc/api/repl.md b/doc/api/repl.md index 09fe9ebcbece61..594c2882998f75 100644 --- a/doc/api/repl.md +++ b/doc/api/repl.md @@ -146,11 +146,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 effects of making +uncaught exceptions not emit the [`'uncaughtException'`][] event. #### Assignment of the `_` (underscore) variable