-
Notifications
You must be signed in to change notification settings - Fork 29.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
process: allow monitoring uncaughtException
Installing an uncaughtException listener has a side effect that process is not aborted. This is quite bad for monitoring/logging tools which tend to be interested in errors but don't want to cause side effects like swallow an exception or change the output on console. There are some workarounds in the wild like monkey patching emit or rethrow in the exception if monitoring tool detects that it is the only listener but this is error prone and risky. This PR allows to install a listener to monitor uncaughtException without the side effect to consider the exception has handled. To avoid conflicts with other events it exports a symbol on process which owns this special meaning.
- Loading branch information
Showing
4 changed files
with
77 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
const theErr = new Error('MyError'); | ||
|
||
process.on( | ||
process.uncaughtExceptionMonitor, | ||
common.mustCall(function onUncaughtExceptionMonitor(err, origin) { | ||
assert.strictEqual(err, theErr); | ||
assert.strictEqual(origin, 'uncaughtException'); | ||
}, 2) | ||
); | ||
|
||
process.on('uncaughtException', common.mustCall( | ||
function onUncaughtException(err, origin) { | ||
assert.strictEqual(origin, 'uncaughtException'); | ||
assert.strictEqual(err, theErr); | ||
}) | ||
); | ||
|
||
process.nextTick(common.mustCall( | ||
function withExceptionCaptureCallback() { | ||
process.setUncaughtExceptionCaptureCallback(common.mustCall( | ||
function uncaughtExceptionCaptureCallback(err) { | ||
assert.strictEqual(err, theErr); | ||
}) | ||
); | ||
|
||
throw theErr; | ||
}) | ||
); | ||
|
||
throw theErr; |