Skip to content
Permalink
Browse files

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...
cjihrig authored and targos committed Jul 5, 2019
1 parent 4cb0fc3 commit a24ab56dc5119d456f7fe354a6ad558f304b64e2
Showing with 31 additions and 2 deletions.
  1. +3 −2 src/node_errors.cc
  2. +28 −0 test/parallel/test-unhandled-exception-rethrow-error.js
@@ -448,10 +448,11 @@ TryCatchScope::~TryCatchScope() {
HandleScope scope(env_->isolate());
Local<v8::Value> exception = Exception();
Local<v8::Message> message = Message();
EnhanceFatalException enhance = CanContinue() ?
EnhanceFatalException::kEnhance : EnhanceFatalException::kDontEnhance;
if (message.IsEmpty())
message = Exception::CreateMessage(env_->isolate(), exception);
ReportFatalException(
env_, exception, message, EnhanceFatalException::kDontEnhance);
ReportFatalException(env_, exception, message, enhance);
env_->Exit(7);
}
}
@@ -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));
}

0 comments on commit a24ab56

Please sign in to comment.
You can’t perform that action at this time.