Skip to content
This repository has been archived by the owner on Jun 18, 2021. It is now read-only.

Commit

Permalink
Fix return code from uncaught exception handler
Browse files Browse the repository at this point in the history
When running on on node 4 and 6, with node-report enabled, the uncaught
exception handler produces a report then prints a stack trace, but node
continues rather than exiting with rc=1. Fix return code and testcase.

PR-URL: #70
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
  • Loading branch information
rnchamberlain committed Mar 16, 2017
1 parent 2c3942d commit fe6cce6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
7 changes: 5 additions & 2 deletions src/module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,9 @@ bool OnUncaughtException(v8::Isolate* isolate) {
(commandline_string.find("abort_on_uncaught_exception") != std::string::npos)) {
return true; // abort required
}
// On V8 versions earlier than 5.4 we need to print the exception backtrace
// to stderr, as V8 does not do so (unless we trigger an abort, as above).
// On versions earlier than 5.4, V8 does not provide the default behaviour
// for uncaught exception on return from this callback. Default behaviour is
// to print a stack trace and exit with rc=1, so we need to mimic that here.
int v8_major, v8_minor;
if (sscanf(v8::V8::GetVersion(), "%d.%d", &v8_major, &v8_minor) == 2) {
if (v8_major < 5 || (v8_major == 5 && v8_minor < 4)) {
Expand All @@ -184,6 +185,8 @@ bool OnUncaughtException(v8::Isolate* isolate) {
// On other platforms use the Message API
Message::PrintCurrentStackTrace(isolate, stderr);
#endif
// exit direct from this callback with rc=1, to mimic V8 behaviour
exit(1);
}
}
return false;
Expand Down
8 changes: 1 addition & 7 deletions test/test-exception.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,7 @@ if (process.argv[2] === 'child') {
});
child.on('exit', (code) => {
tap.plan(4);
// Verify exit code. Note that behaviour changed in V8 v5.4
const v8_version = (process.versions.v8).match(/\d+/g);
if (v8_version[0] < 5 || (v8_version[0] == 5 && v8_version[1] < 4)) {
tap.equal(code, 0, 'Check for expected process exit code');
} else {
tap.equal(code, 1, 'Check for expected process exit code');
}
tap.equal(code, 1, 'Check for expected process exit code');
tap.match(stderr, /myException/,
'Check for expected stack trace frame in stderr');
const reports = common.findReports(child.pid);
Expand Down

0 comments on commit fe6cce6

Please sign in to comment.