@@ -486,7 +486,7 @@ function getErrorSource(error) {
486
486
return null ;
487
487
}
488
488
489
- function printErrorAndExit ( error ) {
489
+ function printFatalErrorUponExit ( error ) {
490
490
var source = getErrorSource ( error ) ;
491
491
492
492
// Ensure error is printed synchronously and not truncated
@@ -505,23 +505,24 @@ function printErrorAndExit (error) {
505
505
colors : process . stderr . isTTY
506
506
} )
507
507
) ;
508
- process . exit ( 1 ) ;
509
508
}
510
509
511
510
function shimEmitUncaughtException ( ) {
512
511
var origEmit = process . emit ;
512
+ var isTerminatingDueToFatalException = false ;
513
+ var fatalException ;
513
514
514
515
process . emit = function ( type ) {
515
- if ( type === 'uncaughtException' ) {
516
- var hasStack = ( arguments [ 1 ] && arguments [ 1 ] . stack ) ;
517
- var hasListeners = ( this . listeners ( type ) . length > 0 ) ;
518
-
519
- if ( hasStack && ! hasListeners ) {
520
- return printErrorAndExit ( arguments [ 1 ] ) ;
521
- }
516
+ const hadListeners = origEmit . apply ( this , arguments ) ;
517
+ if ( type === 'uncaughtException' && ! hadListeners ) {
518
+ isTerminatingDueToFatalException = true ;
519
+ fatalException = arguments [ 1 ] ;
520
+ process . exit ( 1 ) ;
522
521
}
523
-
524
- return origEmit . apply ( this , arguments ) ;
522
+ if ( type === 'exit' && isTerminatingDueToFatalException ) {
523
+ printFatalErrorUponExit ( fatalException ) ;
524
+ }
525
+ return hadListeners ;
525
526
} ;
526
527
}
527
528
0 commit comments