-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src: allow fatal exceptions to be enhanced
This commit allows fatal exceptions to be enhanced so that exceptions thrown from an unhandledException handler have the stack attached properly. PR-URL: #28562 Fixes: #28550 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
- Loading branch information
Showing
2 changed files
with
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
require('../common'); | ||
|
||
if (process.argv[2] === 'child') { | ||
process.on('uncaughtException', (err) => { | ||
err.rethrow = true; | ||
throw err; | ||
}); | ||
|
||
function throwException() { | ||
throw new Error('boom'); | ||
} | ||
|
||
throwException(); | ||
} else { | ||
const assert = require('assert'); | ||
const { spawnSync } = require('child_process'); | ||
const result = spawnSync(process.execPath, [__filename, 'child']); | ||
|
||
assert.strictEqual(result.status, 7); | ||
assert.strictEqual(result.signal, null); | ||
assert.strictEqual(result.stdout.toString().trim(), ''); | ||
// Verify that the error was thrown and that the stack was preserved. | ||
const stderr = result.stderr.toString(); | ||
assert(/Error: boom/.test(stderr)); | ||
assert(/at throwException/.test(stderr)); | ||
assert(/rethrow: true/.test(stderr)); | ||
} |