@@ -19,46 +19,60 @@ const onProcessError = require('on-process-error')
1919const undoSetup = onProcessError .setup ()
2020```
2121
22- When any process errors occur, it will be logged using ` console.error() ` :
22+ When any process errors occur, it will be logged using ` console.error() ` .
23+ The message will include detailed information about the error.
2324
24- - the message will include detailed information about the error
25- - for ` warning ` , ` console.warn() ` will be used instead.
26- - for ` uncaughtException ` , [ ` process.exit(1) ` will be called after
27- ` console.error() ` ] ( https://nodejs.org/api/process.html#process_warning_using_uncaughtexception_correctly ) .
25+ For ` warning ` , ` console.warn() ` will be used instead.
2826
2927You can undo everything by firing the function returned by
3028` onProcessError.setup() ` (called ` undoSetup ` in the example above).
3129
30+ # Example output
31+
32+ TO BE DONE
33+
3234# Custom handling
3335
34- You can override the default behavior by passing a custom function instead.
36+ You can override the default behavior by passing a custom function to the
37+ ` handle ` option.
3538
3639<!-- eslint-disable no-empty-function, no-unused-vars, node/no-missing-require,
37- import/no-unresolved, unicorn/filename-case, strict -->
40+ import/no-unresolved, unicorn/filename-case, strict, no-undef -->
3841
3942``` js
40- const onProcessError = require (' on-process-error' )
41-
42- const undoSetup = onProcessError .setup (
43- ({ eventName, promiseState, promiseValue, error, message }) => {},
44- )
43+ onProcessError .setup ({
44+ handle ({ eventName, promiseState, promiseValue, error, message }) {},
45+ })
4546```
4647
48+ This can be useful if you want to use your own logger instead of the console.
49+
4750The function's argument is an object with the following properties:
4851
4952- ` eventName ` ` {string} ` : can be ` uncaughtException ` , ` unhandledRejection ` ,
5053 ` rejectionHandled ` , ` multipleResolves ` or ` warning `
54+ - ` error ` ` {any} ` is either:
55+ - value thrown by ` uncaughtException ` . Usually an ` Error ` instance, but not
56+ always.
57+ - ` Error ` instance emitted by ` warning ` .
58+ [ ` error.name ` , ` error.code ` and ` error.detail ` ] ( https://nodejs.org/api/process.html#process_event_warning )
59+ might be defined.
5160- ` promiseState ` ` {string} ` : whether promise was ` resolved ` or ` rejected ` .
5261 For ` unhandledRejection ` , ` rejectionHandled ` and ` multipleResolves ` .
5362- ` promiseValue ` ` {any} ` : value resolved/rejected by the promise.
5463 For ` unhandledRejection ` , ` rejectionHandled ` and ` multipleResolves ` .
55- - ` error ` ` {error} ` :
56- - can be:
57- - thrown by ` uncaughtException `
58- - emitted by ` warning ` . [ ` error.name ` , ` error.code ` and ` error.detail ` ] ( https://nodejs.org/api/process.html#process_event_warning )
59- might be defined.
60- - rejected by ` unhandledRejection ` , ` rejectionHandled ` or
61- ` multipleResolves ` 's promise (if the promise was rejected).
62- - if the error is not an ` Error ` instance (e.g. if it is a string), it will
63- be normalized to one using ` new Error() ` .
6464- ` message ` ` {string} ` : detailed message summing up all of the above.
65+
66+ # Exiting on uncaught exceptions
67+
68+ By default, ` uncaughtException ` will fire ` process.exit(1) ` . This is the recommended behavior according to the
69+ [ Node.js documentation] ( https://nodejs.org/api/process.html#process_warning_using_uncaughtexception_correctly ) .
70+
71+ You can disable this by setting the ` exitOnExceptions ` option to ` false ` :
72+
73+ <!-- eslint-disable no-empty-function, no-unused-vars, node/no-missing-require,
74+ import/no-unresolved, unicorn/filename-case, strict, no-undef -->
75+
76+ ``` js
77+ onProcessError .setup ({ exitOnExceptions: false })
78+ ```
0 commit comments