Skip to content

Commit 16ec7bd

Browse files
committed
Some fixes for better error reporting
1 parent cfa38e2 commit 16ec7bd

File tree

4 files changed

+35
-15
lines changed

4 files changed

+35
-15
lines changed

src/commands/workspaces.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,10 @@ export class ConnectInNewWindowCommand implements Command {
133133
localSSHTestSuccess = true;
134134
} catch (e) {
135135
this.telemetryService.sendTelemetryException(
136-
new WrapError('Local SSH: failed to connect to workspace', e, 'Unknown'),
136+
new WrapError('Local SSH: failed to connect to workspace', e),
137137
{
138138
gitpodHost: this.hostService.gitpodHost,
139+
openSSHVersion: await getOpenSSHVersion(),
139140
workspaceId: wsData!.id,
140141
}
141142
);
@@ -183,10 +184,9 @@ export class ConnectInNewWindowCommand implements Command {
183184
this.remoteService.startLocalSSHServiceServer()
184185
]);
185186
} catch (e) {
186-
const openSSHVersion = await getOpenSSHVersion();
187187
this.telemetryService.sendTelemetryException(new WrapError('Local SSH: failed to initialize local SSH', e), {
188188
gitpodHost: this.hostService.gitpodHost,
189-
openSSHVersion,
189+
openSSHVersion: await getOpenSSHVersion(),
190190
workspaceId
191191

192192
});
@@ -297,9 +297,10 @@ export class ConnectInCurrentWindowCommand implements Command {
297297
localSSHTestSuccess = true;
298298
} catch (e) {
299299
this.telemetryService.sendTelemetryException(
300-
new WrapError('Local SSH: failed to connect to workspace', e, 'Unknown'),
300+
new WrapError('Local SSH: failed to connect to workspace', e),
301301
{
302302
gitpodHost: this.hostService.gitpodHost,
303+
openSSHVersion: await getOpenSSHVersion(),
303304
workspaceId: wsData!.id,
304305
}
305306
);
@@ -347,10 +348,9 @@ export class ConnectInCurrentWindowCommand implements Command {
347348
this.remoteService.startLocalSSHServiceServer()
348349
]);
349350
} catch (e) {
350-
const openSSHVersion = await getOpenSSHVersion();
351351
this.telemetryService.sendTelemetryException(new WrapError('Local SSH: failed to initialize local SSH', e), {
352352
gitpodHost: this.hostService.gitpodHost,
353-
openSSHVersion,
353+
openSSHVersion: await getOpenSSHVersion(),
354354
workspaceId
355355

356356
});

src/remote.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,31 @@ export class NoRunningInstanceError extends Error {
2323
code = 'NoRunningInstanceError';
2424
constructor(readonly workspaceId: string, readonly phase?: string) {
2525
super(`Failed to connect to ${workspaceId} Gitpod workspace, workspace not running: ${phase}`);
26+
this.name = 'NoRunningInstanceError'
2627
}
2728
}
2829

2930
export class NoSSHGatewayError extends Error {
3031
code = 'NoSSHGatewayError';
3132
constructor(readonly host: string) {
3233
super(`SSH gateway not configured for this Gitpod Host ${host}`);
34+
this.name = 'NoSSHGatewayError'
3335
}
3436
}
3537

3638
export class NoExtensionIPCServerError extends Error {
3739
code = 'NoExtensionIPCServer';
3840
constructor() {
39-
super('NoExtensionIPCServer');
41+
super('No Extension IPC Server running');
42+
this.name = 'NoExtensionIPCServerError'
4043
}
4144
}
4245

4346
export class NoLocalSSHSupportError extends Error {
4447
code = 'NoLocalSSHSupport';
4548
constructor() {
46-
super('NoLocalSSHSupport');
49+
super('No Local SSH support');
50+
this.name = 'NoLocalSSHSupportError';
4751
}
4852
}
4953

src/remoteConnector.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -716,10 +716,8 @@ export class RemoteConnector extends Disposable {
716716

717717
this.telemetryService.sendUserFlowStatus('connected', localSSHFlow);
718718
} catch (e) {
719-
const reason = e?.code ? e.code : 'Unknown';
720-
if (reason === 'Unknown') {
721-
this.telemetryService.sendTelemetryException(new WrapError('Local SSH: failed to connect to workspace', e, 'Unknown'), { ...localSSHFlow });
722-
}
719+
const reason = e?.code ?? (e?.name && e.name !== 'Error' ? e.name : 'Unknown');
720+
this.telemetryService.sendTelemetryException(new WrapError('Local SSH: failed to connect to workspace', e), { ...localSSHFlow });
723721
this.telemetryService.sendUserFlowStatus('failed', { ...localSSHFlow, reason });
724722
this.logService.error(`Local SSH: failed to connect to ${params.workspaceId} Gitpod workspace:`, e);
725723
}

src/ssh/nativeSSH.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@ export class NativeSSHError extends Error {
1515
}
1616
}
1717

18+
export class SSHOutputVerificationError extends Error {
19+
constructor() {
20+
super();
21+
this.name = 'SSHOutputVerificationError';
22+
this.message = `SSH output verification failed`;
23+
}
24+
}
25+
26+
export class SSHCommandTimeoutError extends Error {
27+
constructor() {
28+
super();
29+
this.name = 'SSHCommandTimeoutError';
30+
this.message = `SSH command timeout`;
31+
}
32+
}
33+
1834
function getSSHConfigPath() {
1935
const sshPath = vscode.workspace.getConfiguration('remote.SSH').get<string>('path');
2036
return sshPath || 'ssh';
@@ -35,7 +51,7 @@ function execCommand(commmad: string, args?: string[], options?: { timeout?: num
3551
reject(err);
3652
});
3753
process.on('close', (code) => {
38-
resolve({ code: code ?? 0 });
54+
resolve({ code: code ?? 256 });
3955
});
4056
})
4157

@@ -95,16 +111,18 @@ export async function testSSHConnection(username: string, hostname: string) {
95111
const sshPath = getSSHConfigPath();
96112
const randomId = crypto.randomBytes(12).toString('hex');
97113
// TODO: support password input so we can replace the ssh2 library
98-
const resp = execCommand(sshPath, ['-T', '-o', 'ConnectTimeout=5', `${username}@${hostname}`, `echo "${randomId}"`], { timeout: 5500 });
114+
const resp = execCommand(sshPath, ['-T', '-o', 'ConnectTimeout=8', `${username}@${hostname}`, `echo "${randomId}"`], { timeout: 8500 });
99115
const { code } = await resp.completed;
100116
if (code === 0) {
101117
// When using ssh gateway sometimes the command output is missing, probably some bug on go code?
102118
// If not then just check for code === 0, works fine with websocket though
103119
if (resp.stdout.includes(randomId)) {
104120
return;
105121
} else {
106-
throw new Error('SSH output verification failed');
122+
throw new SSHOutputVerificationError();
107123
}
124+
} else if (code === 256) {
125+
throw new SSHCommandTimeoutError();
108126
} else {
109127
throw new NativeSSHError(code, resp.stdout, resp.stderr);
110128
}

0 commit comments

Comments
 (0)