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) {
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
504504function 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
You can’t perform that action at this time.
0 commit comments