@@ -35,6 +35,7 @@ import WebSocket = require('ws');
35
35
import { BaseGitpodAnalyticsEventPropeties , GitpodAnalyticsEvent } from './analytics' ;
36
36
import * as uuid from 'uuid' ;
37
37
import { RemoteTrackMessage } from '@gitpod/gitpod-protocol/lib/analytics' ;
38
+ import Log from './common/logger' ;
38
39
39
40
export class SupervisorConnection {
40
41
readonly deadlines = {
@@ -94,7 +95,7 @@ export class GitpodExtensionContext implements vscode.ExtensionContext {
94
95
readonly user : Promise < User > ,
95
96
readonly instanceListener : Promise < WorkspaceInstanceUpdateListener > ,
96
97
readonly workspaceOwned : Promise < boolean > ,
97
- readonly output : vscode . OutputChannel ,
98
+ readonly logger : Log ,
98
99
readonly ipcHookCli : string | undefined
99
100
) {
100
101
this . workspaceContextUrl = vscode . Uri . parse ( info . getWorkspaceContextUrl ( ) ) ;
@@ -168,7 +169,7 @@ export class GitpodExtensionContext implements vscode.ExtensionContext {
168
169
await Promise . allSettled ( this . pendingWillCloseSocket . map ( f => f ( ) ) ) ;
169
170
webSocket . close ( ) ;
170
171
} catch ( e ) {
171
- this . output . appendLine ( 'failed to dispose context: ' + e ) ;
172
+ this . logger . error ( 'failed to dispose context:' , e ) ;
172
173
console . error ( 'failed to dispose context:' , e ) ;
173
174
}
174
175
} ) ( ) ;
@@ -193,20 +194,20 @@ export class GitpodExtensionContext implements vscode.ExtensionContext {
193
194
}
194
195
} ;
195
196
if ( this . devMode && vscode . env . uiKind === vscode . UIKind . Web ) {
196
- this . output . appendLine ( `ANALYTICS: ${ JSON . stringify ( msg ) } ` ) ;
197
+ this . logger . trace ( `ANALYTICS: ${ JSON . stringify ( msg ) } ` ) ;
197
198
return Promise . resolve ( ) ;
198
199
}
199
200
try {
200
201
await this . gitpod . server . trackEvent ( msg ) ;
201
202
} catch ( e ) {
202
- this . output . appendLine ( 'failed to track event: ' + e ) ;
203
+ this . logger . error ( 'failed to track event:' , e ) ;
203
204
console . error ( 'failed to track event:' , e ) ;
204
205
}
205
206
}
206
207
}
207
208
208
209
export async function createGitpodExtensionContext ( context : vscode . ExtensionContext ) : Promise < GitpodExtensionContext | undefined > {
209
- const output = vscode . window . createOutputChannel ( 'Gitpod Workspace' ) ;
210
+ const logger = new Log ( 'Gitpod Workspace' ) ;
210
211
const devMode = context . extensionMode === vscode . ExtensionMode . Development || ! ! process . env [ 'VSCODE_DEV' ] ;
211
212
212
213
const supervisor = new SupervisorConnection ( context ) ;
@@ -222,7 +223,7 @@ export async function createGitpodExtensionContext(context: vscode.ExtensionCont
222
223
contentAvailable = result . getAvailable ( ) ;
223
224
} catch ( e ) {
224
225
if ( e . code === grpc . status . UNAVAILABLE ) {
225
- output . appendLine ( 'It does not look like we are running in a Gitpod workspace, supervisor is not available.' ) ;
226
+ logger . info ( 'It does not look like we are running in a Gitpod workspace, supervisor is not available.' ) ;
226
227
return undefined ;
227
228
}
228
229
console . error ( 'cannot maintain connection to supervisor' , e ) ;
@@ -308,7 +309,7 @@ export async function createGitpodExtensionContext(context: vscode.ExtensionCont
308
309
return workspaceOwned ;
309
310
} ) ( ) ;
310
311
311
- const ipcHookCli = installCLIProxy ( context , output ) ;
312
+ const ipcHookCli = installCLIProxy ( context , logger ) ;
312
313
313
314
const config = await import ( './gitpod-plugin-model' ) ;
314
315
return new GitpodExtensionContext (
@@ -324,7 +325,7 @@ export async function createGitpodExtensionContext(context: vscode.ExtensionCont
324
325
pendingGetUser ,
325
326
pendingInstanceListener ,
326
327
pendingWorkspaceOwned ,
327
- output ,
328
+ logger ,
328
329
ipcHookCli
329
330
) ;
330
331
}
@@ -722,7 +723,7 @@ export function registerDefaultLayout(context: GitpodExtensionContext): void {
722
723
}
723
724
}
724
725
725
- function installCLIProxy ( context : vscode . ExtensionContext , output : vscode . OutputChannel ) : string | undefined {
726
+ function installCLIProxy ( context : vscode . ExtensionContext , logger : Log ) : string | undefined {
726
727
const vscodeIpcHookCli = process . env [ 'VSCODE_IPC_HOOK_CLI' ] ;
727
728
if ( ! vscodeIpcHookCli ) {
728
729
return undefined ;
@@ -772,7 +773,7 @@ function installCLIProxy(context: vscode.ExtensionContext, output: vscode.Output
772
773
fs . promises . unlink ( ipcHookCli )
773
774
) ) ;
774
775
} ) . catch ( e => {
775
- output . appendLine ( 'failed to start cli proxy: ' + e ) ;
776
+ logger . error ( 'failed to start cli proxy: ' + e ) ;
776
777
console . error ( 'failed to start cli proxy:' + e ) ;
777
778
} ) ;
778
779
@@ -815,6 +816,7 @@ export async function registerTasks(context: GitpodExtensionContext, createTermi
815
816
} ) ;
816
817
} catch ( err ) {
817
818
if ( ! ( 'code' in err && err . code === grpc . status . CANCELLED ) ) {
819
+ context . logger . error ( 'code server: listening task updates failed:' , err ) ;
818
820
console . error ( 'code server: listening task updates failed:' , err ) ;
819
821
}
820
822
} finally {
@@ -824,6 +826,11 @@ export async function registerTasks(context: GitpodExtensionContext, createTermi
824
826
await new Promise ( resolve => setTimeout ( resolve , 1000 ) ) ;
825
827
}
826
828
}
829
+ context . logger . trace ( 'Task status:' , [ ...tasks . values ( ) ] . map ( status => {
830
+ const stateMap = { [ TaskState . OPENING ] : 'CLOSED' , [ TaskState . RUNNING ] : 'RUNNING' , [ TaskState . CLOSED ] : 'CLOSED' } ;
831
+ return `\t${ status . getTerminal ( ) } => ${ stateMap [ status . getState ( ) ] } ` ;
832
+ } ) . join ( '\n' ) ) ;
833
+
827
834
if ( token . isCancellationRequested ) {
828
835
return ;
829
836
}
@@ -837,6 +844,7 @@ export async function registerTasks(context: GitpodExtensionContext, createTermi
837
844
taskTerminals . set ( term . getAlias ( ) , term ) ;
838
845
}
839
846
} catch ( e ) {
847
+ context . logger . error ( 'failed to list task terminals:' , e ) ;
840
848
console . error ( 'failed to list task terminals:' , e ) ;
841
849
}
842
850
@@ -922,6 +930,7 @@ function createTaskPty(alias: string, context: GitpodExtensionContext, contextTo
922
930
} catch ( e ) {
923
931
notFound = 'code' in e && e . code === grpc . status . NOT_FOUND ;
924
932
if ( ! token . isCancellationRequested && ! notFound && ! ( 'code' in e && e . code === grpc . status . CANCELLED ) ) {
933
+ context . logger . error ( `${ alias } terminal: listening failed:` , e ) ;
925
934
console . error ( `${ alias } terminal: listening failed:` , e ) ;
926
935
}
927
936
} finally {
@@ -931,9 +940,16 @@ function createTaskPty(alias: string, context: GitpodExtensionContext, contextTo
931
940
return ;
932
941
}
933
942
if ( notFound ) {
943
+ context . logger . trace ( `${ alias } terminal not found` ) ;
934
944
onDidCloseEmitter . fire ( ) ;
935
- } else if ( typeof exitCode === 'number' ) {
945
+ tokenSource . cancel ( ) ;
946
+ return ;
947
+ }
948
+ if ( typeof exitCode === 'number' ) {
949
+ context . logger . trace ( `${ alias } terminal exited with ${ exitCode } ` ) ;
936
950
onDidCloseEmitter . fire ( exitCode ) ;
951
+ tokenSource . cancel ( ) ;
952
+ return ;
937
953
}
938
954
await new Promise ( resolve => setTimeout ( resolve , 2000 ) ) ;
939
955
}
@@ -958,10 +974,12 @@ function createTaskPty(alias: string, context: GitpodExtensionContext, contextTo
958
974
await util . promisify ( context . supervisor . terminal . shutdown . bind ( context . supervisor . terminal , request , context . supervisor . metadata , {
959
975
deadline : Date . now ( ) + context . supervisor . deadlines . short
960
976
} ) ) ( ) ;
977
+ context . logger . trace ( `${ alias } terminal closed` ) ;
961
978
} catch ( e ) {
962
979
if ( e && e . code === grpc . status . NOT_FOUND ) {
963
980
// Swallow, the pty has already been killed
964
981
} else {
982
+ context . logger . error ( `${ alias } terminal: shutdown failed:` , e ) ;
965
983
console . error ( `${ alias } terminal: shutdown failed:` , e ) ;
966
984
}
967
985
}
@@ -985,6 +1003,7 @@ function createTaskPty(alias: string, context: GitpodExtensionContext, contextTo
985
1003
} ) ) ( ) ;
986
1004
} catch ( e ) {
987
1005
if ( e && e . code !== grpc . status . NOT_FOUND ) {
1006
+ context . logger . error ( `${ alias } terminal: write failed:` , e ) ;
988
1007
console . error ( `${ alias } terminal: write failed:` , e ) ;
989
1008
}
990
1009
}
@@ -1012,6 +1031,7 @@ function createTaskPty(alias: string, context: GitpodExtensionContext, contextTo
1012
1031
} ) ) ( ) ;
1013
1032
} catch ( e ) {
1014
1033
if ( e && e . code !== grpc . status . NOT_FOUND ) {
1034
+ context . logger . error ( `${ alias } terminal: resize failed:` , e ) ;
1015
1035
console . error ( `${ alias } terminal: resize failed:` , e ) ;
1016
1036
}
1017
1037
}
@@ -1066,7 +1086,7 @@ async function updateIpcHookCli(context: GitpodExtensionContext): Promise<void>
1066
1086
req . end ( ) ;
1067
1087
} ) ;
1068
1088
} catch ( e ) {
1069
- context . output . appendLine ( 'Failed to update gitpod ipc hook cli: ' + e ) ;
1089
+ context . logger . error ( 'Failed to update gitpod ipc hook cli:' , e ) ;
1070
1090
console . error ( 'Failed to update gitpod ipc hook cli:' , e ) ;
1071
1091
}
1072
1092
}
0 commit comments