Skip to content

Commit 774b8df

Browse files
committed
More feedback
1 parent e15545c commit 774b8df

File tree

1 file changed

+49
-26
lines changed

1 file changed

+49
-26
lines changed

extensions/gitpod/src/remoteConnector.ts

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ function checkRunning(pid: number): true | Error {
6464
}
6565
}
6666

67+
class LocalAppError extends Error {
68+
override name = 'LocalAppError';
69+
70+
constructor(message?: string, readonly logPath?: string) {
71+
super(message);
72+
}
73+
}
74+
6775
export default class RemoteConnector extends Disposable {
6876

6977
public static AUTH_COMPLETE_PATH = '/auth-complete';
@@ -391,7 +399,6 @@ export default class RemoteConnector extends Disposable {
391399

392400
const workspaceInfo = await withServerApi(session.accessToken, serviceUrl.toString(), service => service.server.getWorkspace(workspaceId), this.logger);
393401
if (!workspaceInfo.latestInstance) {
394-
this.logger.error('No running instance for this workspaceId', workspaceId);
395402
throw new Error('no_running_instance');
396403
}
397404

@@ -401,31 +408,29 @@ export default class RemoteConnector extends Disposable {
401408
const sshHostKeyResponse = await fetch(sshHostKeyEndPoint);
402409
if (!sshHostKeyResponse.ok) {
403410
// Gitpod SSH gateway not configured
404-
this.logger.error('SSH gateway not configured for this Gitpod Host', gitpodHost);
405411
throw new Error('no_ssh_gateway');
406412
}
407413

408414
const ownerToken = await withServerApi(session.accessToken, serviceUrl.toString(), service => service.server.getOwnerToken(workspaceId), this.logger);
409415

410416
const sshDestInfo = {
411417
user: `${workspaceId}#${ownerToken}`,
412-
hostName: workspaceUrl.host
418+
// See https://github.com/gitpod-io/gitpod/pull/9786 for reasoning about `.ssh` suffix
419+
hostName: workspaceUrl.host.replace(workspaceId, `${workspaceId}.ssh`)
413420
};
414421

415422
return Buffer.from(JSON.stringify(sshDestInfo), 'utf8').toString('hex');
416423
}
417424

418-
private async getWorkspaceLocalAppSSHDestination(params: SSHConnectionParams): Promise<{ localAppSSHDest?: string; localAppSSHConfigPath?: string; }> {
425+
private async getWorkspaceLocalAppSSHDestination(params: SSHConnectionParams): Promise<{ localAppSSHDest: string; localAppSSHConfigPath: string; }> {
419426
return vscode.window.withProgress({
420427
location: vscode.ProgressLocation.Notification,
421428
cancellable: true,
422429
title: `Connecting to Gitpod workspace: ${params.workspaceId}`
423430
}, async (_, token) => {
424431
let localAppLogPath: string | undefined;
425-
426-
let connection: ResolveSSHConnectionResponse | undefined;
427432
try {
428-
connection = await this.withLocalApp(params.gitpodHost, (client, config) => {
433+
const connection = await this.withLocalApp(params.gitpodHost, (client, config) => {
429434
localAppLogPath = config.logPath;
430435

431436
const request = new ResolveSSHConnectionRequest();
@@ -435,26 +440,18 @@ export default class RemoteConnector extends Disposable {
435440
client.resolveSSHConnection(request, (e, r) => r ? resolve(r) : reject(e))
436441
);
437442
}, token);
438-
} catch (e) {
439-
if (e instanceof Error && e.message !== 'cancelled') {
440-
this.logger.error(`Failed to connect to remote workspace ${params.workspaceId} using local app`, e);
441443

442-
const seeLogs = 'See Logs';
443-
const action = await vscode.window.showErrorMessage(`Failed to connect to remote workspace ${params.workspaceId} using local app`, seeLogs);
444-
if (action === seeLogs) {
445-
this.logger.show();
446-
if (localAppLogPath) {
447-
const document = await vscode.workspace.openTextDocument(vscode.Uri.file(localAppLogPath));
448-
vscode.window.showTextDocument(document);
449-
}
450-
}
444+
return {
445+
localAppSSHDest: connection.getHost(),
446+
localAppSSHConfigPath: connection.getConfigFile()
447+
};
448+
} catch (e) {
449+
if (e instanceof Error && e.message === 'cancelled') {
450+
throw e;
451451
}
452-
}
453452

454-
return {
455-
localAppSSHDest: connection?.getHost(),
456-
localAppSSHConfigPath: connection?.getConfigFile()
457-
};
453+
throw new LocalAppError(e.message, localAppLogPath);
454+
}
458455
});
459456
}
460457

@@ -534,21 +531,47 @@ export default class RemoteConnector extends Disposable {
534531
try {
535532
sshDestination = await this.getWorkspaceSSHDestination(params.workspaceId, params.gitpodHost);
536533
} catch (e) {
537-
if (e instanceof Error && e.message === 'no_running_instance') {
534+
if (e instanceof Error && e.message === 'no_ssh_gateway') {
535+
this.logger.error('SSH gateway not configured for this Gitpod Host', params.gitpodHost);
536+
// Do nothing and continue execution
537+
} else if (e instanceof Error && e.message === 'no_running_instance') {
538+
this.logger.error('No running instance for this workspaceId', params.workspaceId);
538539
vscode.window.showErrorMessage(`Failed to connect to remote workspace: No running instance for '${params.workspaceId}'`);
539540
return;
541+
} else {
542+
this.logger.error(`Failed to connect to remote workspace ${params.workspaceId}`, e);
543+
const seeLogs = 'See Logs';
544+
const action = await vscode.window.showErrorMessage(`Failed to connect to remote workspace ${params.workspaceId}`, seeLogs);
545+
if (action === seeLogs) {
546+
this.logger.show();
547+
}
548+
return;
540549
}
541550
}
542551

543552
const usingSSHGateway = !!sshDestination;
544553
let localAppSSHConfigPath: string | undefined;
545554
if (!usingSSHGateway) {
546-
vscode.window.showInformationMessage(`Falling back connecting to remote workspace using local app. You should update your Gitpod installation [enabling direct SSH access](https://github.com/gitpod-io/gitpod/blob/main/install/installer/docs/workspace-ssh-access.md)`);
555+
vscode.window.showWarningMessage(`${params.gitpodHost} does not support [direct SSH access](https://github.com/gitpod-io/gitpod/blob/main/install/installer/docs/workspace-ssh-access.md), connecting via the deprecated SSH tunnel over WebSocket.`);
547556
try {
548557
const localAppDestData = await this.getWorkspaceLocalAppSSHDestination(params);
549558
sshDestination = localAppDestData.localAppSSHDest;
550559
localAppSSHConfigPath = localAppDestData.localAppSSHConfigPath;
551560
} catch (e) {
561+
this.logger.error(`Failed to connect to remote workspace ${params.workspaceId}`, e);
562+
if (e instanceof LocalAppError) {
563+
const seeLogs = 'See Logs';
564+
const action = await vscode.window.showErrorMessage(`Failed to connect to remote workspace ${params.workspaceId}`, seeLogs);
565+
if (action === seeLogs) {
566+
this.logger.show();
567+
if (e.logPath) {
568+
const document = await vscode.workspace.openTextDocument(vscode.Uri.file(e.logPath));
569+
vscode.window.showTextDocument(document);
570+
}
571+
}
572+
} else {
573+
// Do nothing, user cancelled the operation
574+
}
552575
return;
553576
}
554577
}

0 commit comments

Comments
 (0)