Skip to content

Commit 6cd87b9

Browse files
authored
Add code for errors and report error if unknown IDE-159 (#77)
* Add code for errors and report error if unknown
1 parent 53e7d2f commit 6cd87b9

File tree

2 files changed

+73
-44
lines changed

2 files changed

+73
-44
lines changed

src/remote.ts

Lines changed: 53 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,64 +9,80 @@ import { INotificationService } from './services/notificationService';
99
import { ILogService } from './services/logService';
1010

1111
export interface SSHConnectionParams {
12-
workspaceId: string;
13-
instanceId: string;
14-
gitpodHost: string;
15-
debugWorkspace?: boolean;
16-
connType?: 'local-app' | 'local-ssh' | 'ssh-gateway';
12+
workspaceId: string;
13+
instanceId: string;
14+
gitpodHost: string;
15+
debugWorkspace?: boolean;
16+
connType?: 'local-app' | 'local-ssh' | 'ssh-gateway';
1717
}
1818

1919
export interface WorkspaceRestartInfo {
20-
workspaceId: string;
21-
gitpodHost: string;
20+
workspaceId: string;
21+
gitpodHost: string;
2222
}
2323

2424
export class NoRunningInstanceError extends Error {
25-
constructor(readonly workspaceId: string, readonly phase?: string) {
26-
super(`Failed to connect to ${workspaceId} Gitpod workspace, workspace not running: ${phase}`);
27-
}
25+
code = 'NoRunningInstanceError';
26+
constructor(readonly workspaceId: string, readonly phase?: string) {
27+
super(`Failed to connect to ${workspaceId} Gitpod workspace, workspace not running: ${phase}`);
28+
}
2829
}
2930

3031
export class NoSSHGatewayError extends Error {
31-
constructor(readonly host: string) {
32-
super(`SSH gateway not configured for this Gitpod Host ${host}`);
33-
}
32+
code = 'NoSSHGatewayError';
33+
constructor(readonly host: string) {
34+
super(`SSH gateway not configured for this Gitpod Host ${host}`);
35+
}
36+
}
37+
38+
export class NoExtensionIPCServerError extends Error {
39+
code = 'NoExtensionIPCServer';
40+
constructor() {
41+
super('NoExtensionIPCServer');
42+
}
43+
}
44+
45+
export class NoLocalSSHSupportError extends Error {
46+
code = 'NoLocalSSHSupport';
47+
constructor() {
48+
super('NoLocalSSHSupport');
49+
}
3450
}
3551

3652
export const SSH_DEST_KEY = 'ssh-dest:';
3753

3854
export function getGitpodRemoteWindowConnectionInfo(context: vscode.ExtensionContext): { remoteAuthority: string; connectionInfo: SSHConnectionParams } | undefined {
39-
const remoteUri = vscode.workspace.workspaceFile || vscode.workspace.workspaceFolders?.[0].uri;
40-
if (vscode.env.remoteName === 'ssh-remote' && context.extension.extensionKind === vscode.ExtensionKind.UI && remoteUri) {
41-
const [, sshDestStr] = remoteUri.authority.split('+');
42-
const connectionInfo = context.globalState.get<SSHConnectionParams>(`${SSH_DEST_KEY}${sshDestStr}`);
43-
if (connectionInfo) {
44-
return { remoteAuthority: remoteUri.authority, connectionInfo };
45-
}
46-
}
55+
const remoteUri = vscode.workspace.workspaceFile || vscode.workspace.workspaceFolders?.[0].uri;
56+
if (vscode.env.remoteName === 'ssh-remote' && context.extension.extensionKind === vscode.ExtensionKind.UI && remoteUri) {
57+
const [, sshDestStr] = remoteUri.authority.split('+');
58+
const connectionInfo = context.globalState.get<SSHConnectionParams>(`${SSH_DEST_KEY}${sshDestStr}`);
59+
if (connectionInfo) {
60+
return { remoteAuthority: remoteUri.authority, connectionInfo };
61+
}
62+
}
4763

48-
return undefined;
64+
return undefined;
4965
}
5066

5167
export async function showWsNotRunningDialog(workspaceId: string, gitpodHost: string, flow: UserFlowTelemetryProperties, notificationService: INotificationService, logService: ILogService) {
52-
const msg = `Workspace ${workspaceId} is not running. Please restart the workspace.`;
53-
logService.error(msg);
68+
const msg = `Workspace ${workspaceId} is not running. Please restart the workspace.`;
69+
logService.error(msg);
5470

55-
const workspaceUrl = new URL(gitpodHost);
56-
workspaceUrl.pathname = '/start';
57-
workspaceUrl.hash = workspaceId;
71+
const workspaceUrl = new URL(gitpodHost);
72+
workspaceUrl.pathname = '/start';
73+
workspaceUrl.hash = workspaceId;
5874

59-
const openUrl = 'Restart workspace';
60-
const resp = await notificationService.showErrorMessage(msg, { id: 'ws_not_running', flow, modal: true }, openUrl);
61-
if (resp === openUrl) {
62-
const opened = await vscode.env.openExternal(vscode.Uri.parse(workspaceUrl.toString()));
63-
if (opened) {
64-
vscode.commands.executeCommand('workbench.action.closeWindow');
65-
}
66-
}
75+
const openUrl = 'Restart workspace';
76+
const resp = await notificationService.showErrorMessage(msg, { id: 'ws_not_running', flow, modal: true }, openUrl);
77+
if (resp === openUrl) {
78+
const opened = await vscode.env.openExternal(vscode.Uri.parse(workspaceUrl.toString()));
79+
if (opened) {
80+
vscode.commands.executeCommand('workbench.action.closeWindow');
81+
}
82+
}
6783
}
6884

6985
export function getLocalSSHDomain(gitpodHost: string): string {
70-
const scope = vscode.env.appName.includes('Insiders') ? 'vsi' : 'vss';
71-
return `${scope}.` + (new URL(gitpodHost)).hostname;
86+
const scope = vscode.env.appName.includes('Insiders') ? 'vsi' : 'vss';
87+
return `${scope}.` + (new URL(gitpodHost)).hostname;
7288
}

src/remoteConnector.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { getAgentSock, SSHError, testSSHConnection } from './sshTestConnection';
3333
import { gatherIdentityFiles } from './ssh/identityFiles';
3434
import { isWindows } from './common/platform';
3535
import SSHDestination from './ssh/sshDestination';
36-
import { NoRunningInstanceError, NoSSHGatewayError, SSHConnectionParams, SSH_DEST_KEY, getLocalSSHDomain } from './remote';
36+
import { NoExtensionIPCServerError, NoLocalSSHSupportError, NoRunningInstanceError, NoSSHGatewayError, SSHConnectionParams, SSH_DEST_KEY, getLocalSSHDomain } from './remote';
3737
import { ISessionService } from './services/sessionService';
3838
import { ILogService } from './services/logService';
3939
import { IHostService } from './services/hostService';
@@ -86,6 +86,7 @@ function checkRunning(pid: number): true | Error {
8686
}
8787

8888
class LocalAppError extends Error {
89+
code = 'LocalAppError';
8990
constructor(cause: Error, readonly logPath?: string) {
9091
super();
9192
this.name = cause.name;
@@ -706,20 +707,24 @@ export class RemoteConnector extends Disposable {
706707
this.localSSHService.extensionServerReady()
707708
]);
708709
if (!isExtensionServerReady) {
709-
throw new Error('NoExtensionIPCServer')
710+
throw new NoExtensionIPCServerError();
710711
}
711712
if (!isSupportLocalSSH) {
712-
throw new Error('NoLocalSSHSupport')
713+
throw new NoLocalSSHSupportError();
713714
}
714715
this.logService.info('Going to use lssh');
715716

716717
const { destination } = await this.getLocalSSHWorkspaceSSHDestination(params);
717718
params.connType = 'local-ssh';
718719
sshDestination = destination;
719-
720+
720721
this.telemetryService.sendUserFlowStatus('connected', localSSHFlow);
721722
} catch (e) {
722-
this.telemetryService.sendUserFlowStatus('failed', { ...localSSHFlow, reason: e.toString() });
723+
const reason = (typeof e?.code === 'string') ? e.code : 'Unknown';
724+
if (reason === 'Unknown') {
725+
this.telemetryService.sendTelemetryException(e, { ...localSSHFlow });
726+
}
727+
this.telemetryService.sendUserFlowStatus('failed', { ...localSSHFlow, reason });
723728
this.logService.error(`Local SSH: failed to connect to ${params.workspaceId} Gitpod workspace:`, e);
724729
}
725730
}
@@ -743,7 +748,11 @@ export class RemoteConnector extends Disposable {
743748

744749
this.telemetryService.sendUserFlowStatus('connected', gatewayFlow);
745750
} catch (e) {
746-
this.telemetryService.sendUserFlowStatus('failed', { ...gatewayFlow, reason: e.toString() });
751+
const reason = (typeof e?.code === 'string') ? e.code : 'Unknown';
752+
if (reason === 'Unknown') {
753+
this.telemetryService.sendTelemetryException(e, { ...gatewayFlow });
754+
}
755+
this.telemetryService.sendUserFlowStatus('failed', { ...gatewayFlow, reason });
747756
if (e instanceof NoSSHGatewayError) {
748757
this.logService.error('No SSH gateway:', e);
749758
const ok = 'OK';
@@ -795,7 +804,11 @@ export class RemoteConnector extends Disposable {
795804

796805
this.telemetryService.sendUserFlowStatus('connected', localAppFlow);
797806
} catch (e) {
798-
this.telemetryService.sendUserFlowStatus('failed', { reason: e.toString(), ...localAppFlow });
807+
const reason = (typeof e?.code === 'string') ? e.code : 'Unknown';
808+
if (reason === 'Unknown') {
809+
this.telemetryService.sendTelemetryException(e, { ...localAppFlow });
810+
}
811+
this.telemetryService.sendUserFlowStatus('failed', { reason, ...localAppFlow });
799812
this.logService.error(`Failed to connect ${params.workspaceId} Gitpod workspace:`, e);
800813
if (e instanceof LocalAppError) {
801814
const seeLogs = 'See Logs';

0 commit comments

Comments
 (0)