diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2018-05-17 17:25:36 +0300 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2019-05-08 09:15:15 +0300 |
commit | 422e8f762873aef4a37185f3237c0d666c929d8e (patch) | |
tree | e56695393ab0bfe6445a76541502354506916f29 /doc/api/repl.md | |
parent | 9a174db3d869c8d5cde9e09db92d88d0d97e9513 (diff) |
repl: handle uncaughtException properly
When running the REPL as standalone program it's now possible to use
`process.on('uncaughtException', listener)`. It is going to use those
listeners from now on and the regular error output is suppressed.
It also fixes the issue that REPL instances started inside of an
application would silence all application errors. It is now prohibited
to add the exception listener in such REPL instances. Trying to add
such listeners throws an `ERR_INVALID_REPL_INPUT` error.
Fixes: https://github.com/nodejs/node/issues/19998
PR-URL: https://github.com/nodejs/node/pull/27151
Fixes: https://github.com/nodejs/node/issues/19998
Reviewed-By: Lance Ball <lball@redhat.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'doc/api/repl.md')
-rw-r--r-- | doc/api/repl.md | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/doc/api/repl.md b/doc/api/repl.md index e0ec27b7e3b..563817c6322 100644 --- a/doc/api/repl.md +++ b/doc/api/repl.md @@ -138,16 +138,47 @@ global or scoped variable, the input `fs` will be evaluated on-demand as ``` #### Global Uncaught Exceptions +<!-- YAML +changes: + - version: REPLACEME + pr-url: https://github.com/nodejs/node/pull/27151 + description: The `'uncaughtException'` event is from now on triggered if the + repl is used as standalone program. +--> 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. +* Uncaught exceptions only emit the [`'uncaughtException'`][] event if the + `repl` is used as standalone program. If the `repl` is included anywhere in + another application, adding a listener for this event will throw an + [`ERR_INVALID_REPL_INPUT`][] exception. * Trying to use [`process.setUncaughtExceptionCaptureCallback()`][] throws an [`ERR_DOMAIN_CANNOT_SET_UNCAUGHT_EXCEPTION_CAPTURE`][] error. +As standalone program: + +```js +process.on('uncaughtException', () => console.log('Uncaught')); + +throw new Error('foobar'); +// Uncaught +``` + +When used in another application: + +```js +process.on('uncaughtException', () => console.log('Uncaught')); +// TypeError [ERR_INVALID_REPL_INPUT]: Listeners for `uncaughtException` +// cannot be used in the REPL + +throw new Error('foobar'); +// Thrown: +// Error: foobar +``` + #### Assignment of the `_` (underscore) variable <!-- YAML changes: @@ -661,6 +692,7 @@ For an example of running a REPL instance over [curl(1)][], see: [`'uncaughtException'`]: process.html#process_event_uncaughtexception [`--experimental-repl-await`]: cli.html#cli_experimental_repl_await [`ERR_DOMAIN_CANNOT_SET_UNCAUGHT_EXCEPTION_CAPTURE`]: errors.html#errors_err_domain_cannot_set_uncaught_exception_capture +[`ERR_INVALID_REPL_INPUT`]: errors.html#errors_err_invalid_repl_input [`domain`]: domain.html [`process.setUncaughtExceptionCaptureCallback()`]: process.html#process_process_setuncaughtexceptioncapturecallback_fn [`readline.InterfaceCompleter`]: readline.html#readline_use_of_the_completer_function |