Skip to content

Commit

Permalink
Add checker for in operator
Browse files Browse the repository at this point in the history
  • Loading branch information
mustard-mh committed Nov 1, 2022
1 parent 698bcf9 commit b60c26a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
3 changes: 2 additions & 1 deletion extensions/gitpod-remote/src/ports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as util from 'util';
import { GitpodExtensionContext, GitpodWorkspacePort } from 'gitpod-shared';
import { PortsStatus, PortsStatusRequest, PortsStatusResponse } from '@gitpod/supervisor-api-grpc/lib/status_pb';
import { RetryAutoExposeRequest, TunnelVisiblity } from '@gitpod/supervisor-api-grpc/lib/port_pb';
import { isGRPCErrorStatus } from 'gitpod-shared/src/common/utils';

export async function getSupervisorPorts(context: GitpodExtensionContext) {
let supervisorPortList: PortsStatus.AsObject[] = [];
Expand Down Expand Up @@ -41,7 +42,7 @@ export function observePortsStatus(context: GitpodExtensionContext): [vscode.Eve
evts.on('data', (resp: PortsStatusResponse) => onPortUpdate.fire(resp.getPortsList().map(p => p.toObject())));
});
} catch (err) {
if (!('code' in err && err.code === grpc.status.CANCELLED)) {
if (!isGRPCErrorStatus(err, grpc.status.CANCELLED)) {
context.logger.error('cannot maintain connection to supervisor', err);
console.error('cannot maintain connection to supervisor', err);
}
Expand Down
6 changes: 6 additions & 0 deletions extensions/gitpod-shared/src/common/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

import * as grpc from '@grpc/grpc-js';

export function isGRPCErrorStatus<T extends grpc.status>(err: any, status: T): boolean {
return err && typeof err === 'object' && 'code' in err && err.code === status;
}
11 changes: 6 additions & 5 deletions extensions/gitpod-shared/src/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import * as uuid from 'uuid';
import { RemoteTrackMessage } from '@gitpod/gitpod-protocol/lib/analytics';
import Log from './common/logger';
import { TunnelPortRequest, TunnelVisiblity } from '@gitpod/supervisor-api-grpc/lib/port_pb';
import { isGRPCErrorStatus } from './common/utils';

export class SupervisorConnection {
readonly deadlines = {
Expand Down Expand Up @@ -686,10 +687,10 @@ export function registerNotifications(context: GitpodExtensionContext): void {
});
});
} catch (err) {
if ('code' in err && err.code === grpc.status.UNIMPLEMENTED) {
if (isGRPCErrorStatus(err, grpc.status.UNIMPLEMENTED)) {
console.warn('supervisor does not implement the notification server');
run = false;
} else if (!('code' in err && err.code === grpc.status.CANCELLED)) {
} else if (!isGRPCErrorStatus(err, grpc.status.CANCELLED)) {
console.error('cannot maintain connection to supervisor', err);
}
} finally {
Expand Down Expand Up @@ -822,7 +823,7 @@ export async function registerTasks(context: GitpodExtensionContext): Promise<vo
});
});
} catch (err) {
if (!('code' in err && err.code === grpc.status.CANCELLED)) {
if (!isGRPCErrorStatus(err, grpc.status.CANCELLED)) {
context.logger.error('code server: listening task updates failed:', err);
console.error('code server: listening task updates failed:', err);
}
Expand Down Expand Up @@ -931,8 +932,8 @@ function createTaskPty(alias: string, context: GitpodExtensionContext, contextTo
});
});
} catch (e) {
notFound = 'code' in e && e.code === grpc.status.NOT_FOUND;
if (!token.isCancellationRequested && !notFound && !('code' in e && e.code === grpc.status.CANCELLED)) {
notFound = isGRPCErrorStatus(e, grpc.status.NOT_FOUND);
if (!token.isCancellationRequested && !notFound && !isGRPCErrorStatus(e, grpc.status.CANCELLED)) {
context.logger.error(`${alias} terminal: listening failed:`, e);
console.error(`${alias} terminal: listening failed:`, e);
}
Expand Down
3 changes: 2 additions & 1 deletion extensions/gitpod-web/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { ReleaseNotes } from './releaseNotes';
import { registerWelcomeWalkthroughContribution, WELCOME_WALKTROUGH_KEY } from './welcomeWalktrough';
import { ExperimentalSettings, isUserOverrideSetting } from './experiments';
import { GitpodPortViewProvider } from './portViewProvider';
import { isGRPCErrorStatus } from 'gitpod-shared/src/common/utils';

let gitpodContext: GitpodExtensionContext | undefined;
export async function activate(context: vscode.ExtensionContext) {
Expand Down Expand Up @@ -403,7 +404,7 @@ async function registerPorts(context: GitpodExtensionContext): Promise<void> {
});
});
} catch (err) {
if (!('code' in err && err.code === grpc.status.CANCELLED)) {
if (!isGRPCErrorStatus(err, grpc.status.CANCELLED)) {
context.logger.error('cannot maintain connection to supervisor', err);
console.error('cannot maintain connection to supervisor', err);
}
Expand Down

0 comments on commit b60c26a

Please sign in to comment.