@@ -666,14 +666,10 @@ export async function createServer(address: string | net.AddressInfo | null, arg
666
666
console . warn ( connectionToken . message ) ;
667
667
process . exit ( 1 ) ;
668
668
}
669
- const disposables = new DisposableStore ( ) ;
670
- const { socketServer, instantiationService } = await setupServerServices ( connectionToken , args , REMOTE_DATA_FOLDER , disposables ) ;
671
669
672
- // Set the unexpected error handler after the services have been initialized, to avoid having
673
- // the telemetry service overwrite our handler
674
- let didLogAboutSIGPIPE = false ;
675
- instantiationService . invokeFunction ( ( accessor ) => {
676
- const logService = accessor . get ( ILogService ) ;
670
+ // setting up error handlers, first with console.error, then, once available, using the log service
671
+
672
+ function initUnexpectedErrorHandler ( handler : ( err : any ) => void ) {
677
673
setUnexpectedErrorHandler ( err => {
678
674
// See https://github.com/microsoft/vscode-remote-release/issues/6481
679
675
// In some circumstances, console.error will throw an asynchronous error. This asynchronous error
@@ -682,18 +678,38 @@ export async function createServer(address: string | net.AddressInfo | null, arg
682
678
if ( isSigPipeError ( err ) && err . stack && / u n e x p e c t e d E r r o r H a n d l e r / . test ( err . stack ) ) {
683
679
return ;
684
680
}
685
- logService . error ( err ) ;
686
- } ) ;
687
- process . on ( 'SIGPIPE' , ( ) => {
688
- // See https://github.com/microsoft/vscode-remote-release/issues/6543
689
- // We would normally install a SIGPIPE listener in bootstrap.js
690
- // But in certain situations, the console itself can be in a broken pipe state
691
- // so logging SIGPIPE to the console will cause an infinite async loop
692
- if ( ! didLogAboutSIGPIPE ) {
693
- didLogAboutSIGPIPE = true ;
694
- onUnexpectedError ( new Error ( `Unexpected SIGPIPE` ) ) ;
695
- }
681
+ handler ( err ) ;
696
682
} ) ;
683
+ }
684
+
685
+ const unloggedErrors : any [ ] = [ ] ;
686
+ initUnexpectedErrorHandler ( ( error : any ) => {
687
+ unloggedErrors . push ( error ) ;
688
+ console . error ( error ) ;
689
+ } ) ;
690
+ let didLogAboutSIGPIPE = false ;
691
+ process . on ( 'SIGPIPE' , ( ) => {
692
+ // See https://github.com/microsoft/vscode-remote-release/issues/6543
693
+ // We would normally install a SIGPIPE listener in bootstrap.js
694
+ // But in certain situations, the console itself can be in a broken pipe state
695
+ // so logging SIGPIPE to the console will cause an infinite async loop
696
+ if ( ! didLogAboutSIGPIPE ) {
697
+ didLogAboutSIGPIPE = true ;
698
+ onUnexpectedError ( new Error ( `Unexpected SIGPIPE` ) ) ;
699
+ }
700
+ } ) ;
701
+
702
+ const disposables = new DisposableStore ( ) ;
703
+ const { socketServer, instantiationService } = await setupServerServices ( connectionToken , args , REMOTE_DATA_FOLDER , disposables ) ;
704
+
705
+ // Set the unexpected error handler after the services have been initialized, to avoid having
706
+ // the telemetry service overwrite our handler
707
+ instantiationService . invokeFunction ( ( accessor ) => {
708
+ const logService = accessor . get ( ILogService ) ;
709
+ unloggedErrors . forEach ( error => logService . error ( error ) ) ;
710
+ unloggedErrors . length = 0 ;
711
+
712
+ initUnexpectedErrorHandler ( ( error : any ) => logService . error ( error ) ) ;
697
713
} ) ;
698
714
699
715
//
0 commit comments