-
-
Notifications
You must be signed in to change notification settings - Fork 32k
process: allow monitoring uncaughtException #31257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Flarna
wants to merge
10
commits into
nodejs:master
from
dynatrace-oss-contrib:uncaughtExceptionMonitor
Closed
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9039128
process: allow monitoring uncaughtException
Flarna df03daa
fixup! crlf => lf
Flarna b58dd7c
use arrow functions
Flarna 6f53695
add test to verify default exit behavior is unchanged
Flarna acee3de
fixup! improve fixture
Flarna 5daab4d
replace symbol uncaughtExceptionMonitor by a string
Flarna c3b5f2d
add test to verify that throwing in monitoring listener results in
Flarna 9db2da6
Update doc/api/process.md
Flarna 4206027
Update doc/api/process.md
Flarna efedbb5
Update doc/api/process.md
Flarna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,7 @@ | ||
'use strict'; | ||
|
||
process.on(process.uncaughtExceptionMonitor, (err) => { | ||
console.log(`Monitored: ${err.message}`); | ||
Flarna marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
|
||
Flarna marked this conversation as resolved.
Show resolved
Hide resolved
|
||
throw new Error('Shall exit'); |
This file contains hidden or 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,49 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const { execFile } = require('child_process'); | ||
const fixtures = require('../common/fixtures'); | ||
|
||
{ | ||
// Verify exit behavior is unchanged | ||
const fixture = fixtures.path('uncaught-exceptions', 'uncaught-monitor.js'); | ||
execFile( | ||
process.execPath, | ||
[fixture], | ||
common.mustCall((err, stdout, stderr) => { | ||
assert.strictEqual(err.code, 1); | ||
assert.strictEqual(Object.getPrototypeOf(err).name, 'Error'); | ||
assert.strictEqual(stdout, 'Monitored: Shall exit\n'); | ||
const errLines = stderr.trim().split(/[\r\n]+/); | ||
const errLine = errLines.find((l) => /^Error/.exec(l)); | ||
assert.strictEqual(errLine, 'Error: Shall exit'); | ||
}) | ||
); | ||
} | ||
|
||
const theErr = new Error('MyError'); | ||
|
||
process.on( | ||
process.uncaughtExceptionMonitor, | ||
common.mustCall((err, origin) => { | ||
assert.strictEqual(err, theErr); | ||
assert.strictEqual(origin, 'uncaughtException'); | ||
}, 2) | ||
); | ||
|
||
process.on('uncaughtException', common.mustCall((err, origin) => { | ||
assert.strictEqual(origin, 'uncaughtException'); | ||
assert.strictEqual(err, theErr); | ||
})); | ||
|
||
process.nextTick(common.mustCall(() => { | ||
// Test with uncaughtExceptionCaptureCallback installed | ||
process.setUncaughtExceptionCaptureCallback(common.mustCall( | ||
(err) => assert.strictEqual(err, theErr)) | ||
); | ||
|
||
throw theErr; | ||
})); | ||
|
||
throw theErr; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.