File tree Expand file tree Collapse file tree 1 file changed +12
-10
lines changed Expand file tree Collapse file tree 1 file changed +12
-10
lines changed Original file line number Diff line number Diff line change @@ -485,7 +485,7 @@ function getErrorSource(error) {
485
485
return null ;
486
486
}
487
487
488
- function printErrorAndExit ( error ) {
488
+ function printFatalErrorUponExit ( error ) {
489
489
var source = getErrorSource ( error ) ;
490
490
491
491
// Ensure error is printed synchronously and not truncated
@@ -503,18 +503,20 @@ function printErrorAndExit (error) {
503
503
504
504
function shimEmitUncaughtException ( ) {
505
505
var origEmit = process . emit ;
506
+ var isTerminatingDueToFatalException = false ;
507
+ var fatalException ;
506
508
507
509
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 ) ;
515
515
}
516
-
517
- return origEmit . apply ( this , arguments ) ;
516
+ if ( type === 'exit' && isTerminatingDueToFatalException ) {
517
+ printFatalErrorUponExit ( fatalException ) ;
518
+ }
519
+ return hadListeners ;
518
520
} ;
519
521
}
520
522
You can’t perform that action at this time.
0 commit comments