summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2019-03-11 20:46:43 +0100
committerRuben Bridgewater <ruben@bridgewater.de>2019-04-15 18:29:07 +0200
commit9dcc9b6a6b3b8ab40be91b2fdc6fdf514e48dcc3 (patch)
treeb715c7140d05728acc5237d12b22eee7e2d0caff /doc
parent2755471bf3ce35a14cb348d4fbf0d34779426e66 (diff)
downloadandroid-node-v8-9dcc9b6a6b3b8ab40be91b2fdc6fdf514e48dcc3.tar.gz
android-node-v8-9dcc9b6a6b3b8ab40be91b2fdc6fdf514e48dcc3.tar.bz2
android-node-v8-9dcc9b6a6b3b8ab40be91b2fdc6fdf514e48dcc3.zip
process: add --unhandled-rejections flag
This adds a flag to define the default behavior for unhandled rejections. Three modes exist: `none`, `warn` and `strict`. The first is going to silence all unhandled rejection warnings. The second behaves identical to the current default with the excetion that no deprecation warning will be printed and the last is going to throw an error for each unhandled rejection, just as regular exceptions do. It is possible to intercept those with the `uncaughtException` hook as with all other exceptions as well. This PR has no influence on the existing `unhandledRejection` hook. If that is used, it will continue to function as before. PR-URL: https://github.com/nodejs/node/pull/26599 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Matheus Marchini <mat@mmarchini.me> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Diffstat (limited to 'doc')
-rw-r--r--doc/api/cli.md19
-rw-r--r--doc/api/process.md37
-rw-r--r--doc/node.13
3 files changed, 44 insertions, 15 deletions
diff --git a/doc/api/cli.md b/doc/api/cli.md
index 60d75a6c04..f56eb981a9 100644
--- a/doc/api/cli.md
+++ b/doc/api/cli.md
@@ -577,6 +577,23 @@ added: v2.4.0
Track heap object allocations for heap snapshots.
+### `--unhandled-rejections=mode`
+<!-- YAML
+added: REPLACEME
+-->
+
+By default all unhandled rejections trigger a warning plus a deprecation warning
+for the very first unhandled rejection in case no [`unhandledRejection`][] hook
+is used.
+
+Using this flag allows to change what should happen when an unhandled rejection
+occurs. One of three modes can be chosen:
+
+* `strict`: Raise the unhandled rejection as an uncaught exception.
+* `warn`: Always trigger a warning, no matter if the [`unhandledRejection`][]
+ hook is set or not but do not print the deprecation warning.
+* `none`: Silence all warnings.
+
### `--use-bundled-ca`, `--use-openssl-ca`
<!-- YAML
added: v6.11.0
@@ -798,6 +815,7 @@ Node.js options that are allowed are:
- `--trace-sync-io`
- `--trace-warnings`
- `--track-heap-objects`
+- `--unhandled-rejections`
- `--use-bundled-ca`
- `--use-openssl-ca`
- `--v8-pool-size`
@@ -966,6 +984,7 @@ greater than `4` (its current default value). For more information, see the
[`process.setUncaughtExceptionCaptureCallback()`]: process.html#process_process_setuncaughtexceptioncapturecallback_fn
[`tls.DEFAULT_MAX_VERSION`]: tls.html#tls_tls_default_max_version
[`tls.DEFAULT_MIN_VERSION`]: tls.html#tls_tls_default_min_version
+[`unhandledRejection`]: process.html#process_event_unhandledrejection
[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/process.md b/doc/api/process.md
index 5eabb6fad1..95f57f6932 100644
--- a/doc/api/process.md
+++ b/doc/api/process.md
@@ -205,8 +205,17 @@ most convenient for scripts).
### Event: 'uncaughtException'
<!-- YAML
added: v0.1.18
+changes:
+ - version: REPLACEME
+ pr-url: https://github.com/nodejs/node/pull/26599
+ description: Added the `origin` argument.
-->
+* `err` {Error} The uncaught exception.
+* `origin` {string} Indicates if the exception originates from an unhandled
+ rejection or from synchronous errors. Can either be `'uncaughtException'` or
+ `'unhandledRejection'`.
+
The `'uncaughtException'` event is emitted when an uncaught JavaScript
exception bubbles all the way back to the event loop. By default, Node.js
handles such exceptions by printing the stack trace to `stderr` and exiting
@@ -217,12 +226,13 @@ behavior. Alternatively, change the [`process.exitCode`][] in the
provided exit code. Otherwise, in the presence of such handler the process will
exit with 0.
-The listener function is called with the `Error` object passed as the only
-argument.
-
```js
-process.on('uncaughtException', (err) => {
- fs.writeSync(1, `Caught exception: ${err}\n`);
+process.on('uncaughtException', (err, origin) => {
+ fs.writeSync(
+ process.stderr.fd,
+ `Caught exception: ${err}\n` +
+ `Exception origin: ${origin}`
+ );
});
setTimeout(() => {
@@ -274,6 +284,10 @@ changes:
a process warning.
-->
+* `reason` {Error|any} The object with which the promise was rejected
+ (typically an [`Error`][] object).
+* `promise` {Promise} The rejected promise.
+
The `'unhandledRejection'` event is emitted whenever a `Promise` is rejected and
no error handler is attached to the promise within a turn of the event loop.
When programming with Promises, exceptions are encapsulated as "rejected
@@ -282,15 +296,9 @@ are propagated through a `Promise` chain. The `'unhandledRejection'` event is
useful for detecting and keeping track of promises that were rejected whose
rejections have not yet been handled.
-The listener function is called with the following arguments:
-
-* `reason` {Error|any} The object with which the promise was rejected
- (typically an [`Error`][] object).
-* `p` the `Promise` that was rejected.
-
```js
-process.on('unhandledRejection', (reason, p) => {
- console.log('Unhandled Rejection at:', p, 'reason:', reason);
+process.on('unhandledRejection', (reason, promise) => {
+ console.log('Unhandled Rejection at:', promise, 'reason:', reason);
// Application specific logging, throwing an error, or other logic here
});
@@ -317,7 +325,7 @@ as would typically be the case for other `'unhandledRejection'` events. To
address such failures, a non-operational
[`.catch(() => { })`][`promise.catch()`] handler may be attached to
`resource.loaded`, which would prevent the `'unhandledRejection'` event from
-being emitted. Alternatively, the [`'rejectionHandled'`][] event may be used.
+being emitted.
### Event: 'warning'
<!-- YAML
@@ -2282,7 +2290,6 @@ cases:
[`'exit'`]: #process_event_exit
[`'message'`]: child_process.html#child_process_event_message
-[`'rejectionHandled'`]: #process_event_rejectionhandled
[`'uncaughtException'`]: #process_event_uncaughtexception
[`ChildProcess.disconnect()`]: child_process.html#child_process_subprocess_disconnect
[`ChildProcess.send()`]: child_process.html#child_process_subprocess_send_message_sendhandle_options_callback
diff --git a/doc/node.1 b/doc/node.1
index 0fccabc4bc..e2b52b9e87 100644
--- a/doc/node.1
+++ b/doc/node.1
@@ -292,6 +292,9 @@ Print stack traces for process warnings (including deprecations).
.It Fl -track-heap-objects
Track heap object allocations for heap snapshots.
.
+.It Fl --unhandled-rejections=mode
+Define the behavior for unhandled rejections. Can be one of `strict` (raise an error), `warn` (enforce warnings) or `none` (silence warnings).
+.
.It Fl -use-bundled-ca , Fl -use-openssl-ca
Use bundled Mozilla CA store as supplied by current Node.js version or use OpenSSL's default CA store.
The default store is selectable at build-time.