Skip to content

Commit d145a92

Browse files
committed
Fix #15
1 parent d354453 commit d145a92

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

source-map-support.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ function getErrorSource(error) {
485485
return null;
486486
}
487487

488-
function printErrorAndExit (error) {
488+
function printFatalErrorUponExit (error) {
489489
var source = getErrorSource(error);
490490

491491
// Ensure error is printed synchronously and not truncated
@@ -503,18 +503,20 @@ function printErrorAndExit (error) {
503503

504504
function shimEmitUncaughtException () {
505505
var origEmit = process.emit;
506+
var isTerminatingDueToFatalException = false;
507+
var fatalException;
506508

507509
process.emit = function (type) {
508-
if (type === 'uncaughtException') {
509-
var hasStack = (arguments[1] && arguments[1].stack);
510-
var hasListeners = (this.listeners(type).length > 0);
511-
512-
if (hasStack && !hasListeners) {
513-
return printErrorAndExit(arguments[1]);
514-
}
510+
const hadListeners = origEmit.apply(this, arguments);
511+
if (type === 'uncaughtException' && !hadListeners) {
512+
isTerminatingDueToFatalException = true;
513+
fatalException = arguments[0];
514+
process.exit(1);
515515
}
516-
517-
return origEmit.apply(this, arguments);
516+
if (type === 'exit' && isTerminatingDueToFatalException) {
517+
printFatalErrorUponExit(fatalException);
518+
}
519+
return hadListeners;
518520
};
519521
}
520522

0 commit comments

Comments
 (0)