diff --git a/components/dashboard/src/components/UsageLimitReachedModal.tsx b/components/dashboard/src/components/UsageLimitReachedModal.tsx
index fc6a2c36c7ca0d..4897a18427aae0 100644
--- a/components/dashboard/src/components/UsageLimitReachedModal.tsx
+++ b/components/dashboard/src/components/UsageLimitReachedModal.tsx
@@ -9,7 +9,7 @@ import Alert from "./Alert";
import Modal from "./Modal";
import { Heading2 } from "./typography/headings";
-export function UsageLimitReachedModal(p: { hints: any; onClose?: () => void }) {
+export function UsageLimitReachedModal(p: { onClose?: () => void }) {
const currentOrg = useCurrentOrg();
const orgName = currentOrg.data?.name;
diff --git a/components/dashboard/src/start/StartPage.tsx b/components/dashboard/src/start/StartPage.tsx
index eaaf8eba6b3f6c..8002c2bf024475 100644
--- a/components/dashboard/src/start/StartPage.tsx
+++ b/components/dashboard/src/start/StartPage.tsx
@@ -111,9 +111,7 @@ export function StartPage(props: StartPageProps) {
)}
{error && error.code === ErrorCodes.NEEDS_VERIFICATION && }
- {error && error.code === ErrorCodes.PAYMENT_SPENDING_LIMIT_REACHED && (
-
- )}
+ {error && error.code === ErrorCodes.PAYMENT_SPENDING_LIMIT_REACHED && }
{error && }
{props.children}
= ({ error, reset, setS
case ErrorCodes.INVALID_COST_CENTER:
return ;
case ErrorCodes.PAYMENT_SPENDING_LIMIT_REACHED:
- return ;
+ return ;
case ErrorCodes.NEEDS_VERIFICATION:
return ;
default:
diff --git a/components/gitpod-protocol/src/messaging/error.ts b/components/gitpod-protocol/src/messaging/error.ts
index cd81832898971e..863ffc1cb0e2a9 100644
--- a/components/gitpod-protocol/src/messaging/error.ts
+++ b/components/gitpod-protocol/src/messaging/error.ts
@@ -5,9 +5,15 @@
*/
import { scrubber } from "../util/scrubbing";
+import { PlainMessage } from "@bufbuild/protobuf";
+import {
+ InvalidGitpodYMLError as InvalidGitpodYMLErrorData,
+ RepositoryNotFoundError as RepositoryNotFoundErrorData,
+ RepositoryUnauthorizedError as RepositoryUnauthorizedErrorData,
+} from "@gitpod/public-api/lib/gitpod/v1/error_pb";
export class ApplicationError extends Error {
- constructor(public readonly code: ErrorCode, message: string, public readonly data?: any) {
+ constructor(readonly code: ErrorCode, readonly message: string, readonly data?: any) {
super(message);
this.data = scrubber.scrub(this.data, true);
}
@@ -21,6 +27,25 @@ export class ApplicationError extends Error {
}
}
+export class RepositoryNotFoundError extends ApplicationError {
+ constructor(readonly info: PlainMessage) {
+ // on gRPC we remap to PRECONDITION_FAILED, all error code for backwards compatibility with the dashboard
+ super(ErrorCodes.NOT_FOUND, "Repository not found.", info);
+ }
+}
+export class UnauthorizedRepositoryAccessError extends ApplicationError {
+ constructor(readonly info: PlainMessage) {
+ // on gRPC we remap to PRECONDITION_FAILED, all error code for backwards compatibility with the dashboard
+ super(ErrorCodes.NOT_AUTHENTICATED, "Repository unauthorized.", info);
+ }
+}
+export class InvalidGitpodYMLError extends ApplicationError {
+ constructor(readonly info: PlainMessage) {
+ // on gRPC we remap to PRECONDITION_FAILED, all error code for backwards compatibility with the dashboard
+ super(ErrorCodes.INVALID_GITPOD_YML, "Invalid gitpod.yml: " + info.violations.join(","), info);
+ }
+}
+
export namespace ApplicationError {
export function hasErrorCode(e: any): e is Error & { code: ErrorCode; data?: any } {
return ErrorCode.is(e["code"]);
diff --git a/components/gitpod-protocol/src/public-api-converter.ts b/components/gitpod-protocol/src/public-api-converter.ts
index 1f8027edda04c3..5e73fa342bffed 100644
--- a/components/gitpod-protocol/src/public-api-converter.ts
+++ b/components/gitpod-protocol/src/public-api-converter.ts
@@ -4,8 +4,21 @@
* See License.AGPL.txt in the project root for license information.
*/
-import { Timestamp } from "@bufbuild/protobuf";
+import { Timestamp, toPlainMessage } from "@bufbuild/protobuf";
import { Code, ConnectError } from "@connectrpc/connect";
+import {
+ FailedPreconditionDetails,
+ ImageBuildLogsNotYetAvailableError,
+ InvalidCostCenterError as InvalidCostCenterErrorData,
+ InvalidGitpodYMLError as InvalidGitpodYMLErrorData,
+ NeedsVerificationError,
+ PaymentSpendingLimitReachedError,
+ PermissionDeniedDetails,
+ RepositoryNotFoundError as RepositoryNotFoundErrorData,
+ RepositoryUnauthorizedError as RepositoryUnauthorizedErrorData,
+ TooManyRunningWorkspacesError,
+ UserBlockedError,
+} from "@gitpod/public-api/lib/gitpod/v1/error_pb";
import {
AuthProvider,
AuthProviderDescription,
@@ -50,7 +63,13 @@ import {
PrebuildPhase,
PrebuildPhase_Phase,
} from "@gitpod/public-api/lib/gitpod/v1/prebuild_pb";
-import { ApplicationError, ErrorCode, ErrorCodes } from "./messaging/error";
+import {
+ ApplicationError,
+ ErrorCodes,
+ InvalidGitpodYMLError,
+ RepositoryNotFoundError,
+ UnauthorizedRepositoryAccessError,
+} from "./messaging/error";
import {
AuthProviderEntry as AuthProviderProtocol,
AuthProviderInfo,
@@ -74,7 +93,6 @@ import {
Project,
Organization as ProtocolOrganization,
} from "./teams-projects-protocol";
-import { TrustedValue } from "./util/scrubbing";
import {
ConfigurationIdeConfig,
PortProtocol,
@@ -84,9 +102,6 @@ import {
} from "./workspace-instance";
import { Author, Commit } from "@gitpod/public-api/lib/gitpod/v1/scm_pb";
-const applicationErrorCode = "application-error-code";
-const applicationErrorData = "application-error-data";
-
/**
* Converter between gRPC and JSON-RPC types.
*
@@ -191,57 +206,240 @@ export class PublicAPIConverter {
return reason;
}
if (reason instanceof ApplicationError) {
- const metadata: HeadersInit = {};
- metadata[applicationErrorCode] = String(reason.code);
- if (reason.data) {
- metadata[applicationErrorData] = JSON.stringify(reason.data);
- }
if (reason.code === ErrorCodes.NOT_FOUND) {
- return new ConnectError(reason.message, Code.NotFound, metadata, undefined, reason);
+ return new ConnectError(reason.message, Code.NotFound, undefined, undefined, reason);
}
if (reason.code === ErrorCodes.NOT_AUTHENTICATED) {
- return new ConnectError(reason.message, Code.Unauthenticated, metadata, undefined, reason);
+ return new ConnectError(reason.message, Code.Unauthenticated, undefined, undefined, reason);
+ }
+ if (reason.code === ErrorCodes.USER_BLOCKED) {
+ return new ConnectError(
+ reason.message,
+ Code.PermissionDenied,
+ undefined,
+ [
+ new PermissionDeniedDetails({
+ reason: {
+ case: "userBlocked",
+ value: new UserBlockedError(),
+ },
+ }),
+ ],
+ reason,
+ );
+ }
+ if (reason.code === ErrorCodes.NEEDS_VERIFICATION) {
+ return new ConnectError(
+ reason.message,
+ Code.PermissionDenied,
+ undefined,
+ [
+ new PermissionDeniedDetails({
+ reason: {
+ case: "needsVerification",
+ value: new NeedsVerificationError(),
+ },
+ }),
+ ],
+ reason,
+ );
}
- if (reason.code === ErrorCodes.PERMISSION_DENIED || reason.code === ErrorCodes.USER_BLOCKED) {
- return new ConnectError(reason.message, Code.PermissionDenied, metadata, undefined, reason);
+ if (reason.code === ErrorCodes.PERMISSION_DENIED) {
+ return new ConnectError(reason.message, Code.PermissionDenied, undefined, undefined, reason);
}
if (reason.code === ErrorCodes.CONFLICT) {
- return new ConnectError(reason.message, Code.AlreadyExists, metadata, undefined, reason);
+ return new ConnectError(reason.message, Code.AlreadyExists, undefined, undefined, reason);
+ }
+ if (reason instanceof InvalidGitpodYMLError) {
+ return new ConnectError(
+ reason.message,
+ Code.FailedPrecondition,
+ undefined,
+ [
+ new FailedPreconditionDetails({
+ reason: {
+ case: "invalidGitpodYml",
+ value: new InvalidGitpodYMLErrorData(reason.info),
+ },
+ }),
+ ],
+ reason,
+ );
+ }
+ if (reason instanceof RepositoryNotFoundError) {
+ return new ConnectError(
+ reason.message,
+ Code.FailedPrecondition,
+ undefined,
+ [
+ new FailedPreconditionDetails({
+ reason: {
+ case: "repositoryNotFound",
+ value: new RepositoryNotFoundErrorData(reason.info),
+ },
+ }),
+ ],
+ reason,
+ );
+ }
+ if (reason instanceof UnauthorizedRepositoryAccessError) {
+ return new ConnectError(
+ reason.message,
+ Code.FailedPrecondition,
+ undefined,
+ [
+ new FailedPreconditionDetails({
+ reason: {
+ case: "repositoryUnauthorized",
+ value: new RepositoryUnauthorizedErrorData(reason.info),
+ },
+ }),
+ ],
+ reason,
+ );
+ }
+ if (reason.code === ErrorCodes.PAYMENT_SPENDING_LIMIT_REACHED) {
+ return new ConnectError(
+ reason.message,
+ Code.FailedPrecondition,
+ undefined,
+ [
+ new FailedPreconditionDetails({
+ reason: {
+ case: "paymentSpendingLimitReached",
+ value: new PaymentSpendingLimitReachedError(),
+ },
+ }),
+ ],
+ reason,
+ );
+ }
+ if (reason.code === ErrorCodes.INVALID_COST_CENTER) {
+ return new ConnectError(
+ reason.message,
+ Code.FailedPrecondition,
+ undefined,
+ [
+ new FailedPreconditionDetails({
+ reason: {
+ case: "invalidCostCenter",
+ value: new InvalidCostCenterErrorData({
+ attributionId: reason.data.attributionId,
+ }),
+ },
+ }),
+ ],
+ reason,
+ );
+ }
+ if (reason.code === ErrorCodes.HEADLESS_LOG_NOT_YET_AVAILABLE) {
+ return new ConnectError(
+ reason.message,
+ Code.FailedPrecondition,
+ undefined,
+ [
+ new FailedPreconditionDetails({
+ reason: {
+ case: "imageBuildLogsNotYetAvailable",
+ value: new ImageBuildLogsNotYetAvailableError(),
+ },
+ }),
+ ],
+ reason,
+ );
+ }
+ if (reason.code === ErrorCodes.TOO_MANY_RUNNING_WORKSPACES) {
+ return new ConnectError(
+ reason.message,
+ Code.FailedPrecondition,
+ undefined,
+ [
+ new FailedPreconditionDetails({
+ reason: {
+ case: "tooManyRunningWorkspaces",
+ value: new TooManyRunningWorkspacesError(),
+ },
+ }),
+ ],
+ reason,
+ );
}
if (reason.code === ErrorCodes.PRECONDITION_FAILED) {
- return new ConnectError(reason.message, Code.FailedPrecondition, metadata, undefined, reason);
+ return new ConnectError(reason.message, Code.FailedPrecondition, undefined, undefined, reason);
}
if (reason.code === ErrorCodes.TOO_MANY_REQUESTS) {
- return new ConnectError(reason.message, Code.ResourceExhausted, metadata, undefined, reason);
- }
- if (reason.code === ErrorCodes.INTERNAL_SERVER_ERROR) {
- return new ConnectError(reason.message, Code.Internal, metadata, undefined, reason);
+ return new ConnectError(reason.message, Code.ResourceExhausted, undefined, undefined, reason);
}
if (reason.code === ErrorCodes.CANCELLED) {
- return new ConnectError(reason.message, Code.DeadlineExceeded, metadata, undefined, reason);
+ return new ConnectError(reason.message, Code.Canceled, undefined, undefined, reason);
}
- return new ConnectError(reason.message, Code.InvalidArgument, metadata, undefined, reason);
+ if (reason.code === ErrorCodes.INTERNAL_SERVER_ERROR) {
+ return new ConnectError(reason.message, Code.Internal, undefined, undefined, reason);
+ }
+ return new ConnectError(reason.message, Code.Unknown, undefined, undefined, reason);
}
return ConnectError.from(reason, Code.Internal);
}
fromError(reason: ConnectError): Error {
- const codeMetadata = reason.metadata?.get(applicationErrorCode);
- if (!codeMetadata) {
- return reason;
- }
- const code = Number(codeMetadata) as ErrorCode;
- const dataMetadata = reason.metadata?.get(applicationErrorData);
- let data = undefined;
- if (dataMetadata) {
- try {
- data = JSON.parse(dataMetadata);
- } catch (e) {
- console.error("failed to parse application error data", e);
+ if (reason.code === Code.NotFound) {
+ return new ApplicationError(ErrorCodes.NOT_FOUND, reason.rawMessage);
+ }
+ if (reason.code === Code.Unauthenticated) {
+ return new ApplicationError(ErrorCodes.NOT_AUTHENTICATED, reason.rawMessage);
+ }
+ if (reason.code === Code.PermissionDenied) {
+ const details = reason.findDetails(PermissionDeniedDetails)[0];
+ switch (details?.reason?.case) {
+ case "userBlocked":
+ return new ApplicationError(ErrorCodes.USER_BLOCKED, reason.rawMessage);
+ case "needsVerification":
+ return new ApplicationError(ErrorCodes.NEEDS_VERIFICATION, reason.rawMessage);
+ }
+ return new ApplicationError(ErrorCodes.PERMISSION_DENIED, reason.rawMessage);
+ }
+ if (reason.code === Code.AlreadyExists) {
+ return new ApplicationError(ErrorCodes.CONFLICT, reason.rawMessage);
+ }
+ if (reason.code === Code.FailedPrecondition) {
+ const details = reason.findDetails(FailedPreconditionDetails)[0];
+ switch (details?.reason?.case) {
+ case "invalidGitpodYml":
+ const invalidGitpodYmlInfo = toPlainMessage(details.reason.value);
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
+ return new InvalidGitpodYMLError(invalidGitpodYmlInfo);
+ case "repositoryNotFound":
+ const repositoryNotFoundInfo = toPlainMessage(details.reason.value);
+ return new RepositoryNotFoundError(repositoryNotFoundInfo);
+ case "repositoryUnauthorized":
+ const repositoryUnauthorizedInfo = toPlainMessage(details.reason.value);
+ return new UnauthorizedRepositoryAccessError(repositoryUnauthorizedInfo);
+ case "paymentSpendingLimitReached":
+ return new ApplicationError(ErrorCodes.PAYMENT_SPENDING_LIMIT_REACHED, reason.rawMessage);
+ case "invalidCostCenter":
+ const invalidCostCenterInfo = toPlainMessage(details.reason.value);
+ return new ApplicationError(
+ ErrorCodes.INVALID_COST_CENTER,
+ reason.rawMessage,
+ invalidCostCenterInfo,
+ );
+ case "imageBuildLogsNotYetAvailable":
+ return new ApplicationError(ErrorCodes.HEADLESS_LOG_NOT_YET_AVAILABLE, reason.rawMessage);
+ case "tooManyRunningWorkspaces":
+ return new ApplicationError(ErrorCodes.TOO_MANY_RUNNING_WORKSPACES, reason.rawMessage);
}
+ return new ApplicationError(ErrorCodes.PRECONDITION_FAILED, reason.rawMessage);
+ }
+ if (reason.code === Code.ResourceExhausted) {
+ return new ApplicationError(ErrorCodes.TOO_MANY_REQUESTS, reason.rawMessage);
+ }
+ if (reason.code === Code.Canceled) {
+ return new ApplicationError(ErrorCodes.CANCELLED, reason.rawMessage);
+ }
+ if (reason.code === Code.Internal) {
+ return new ApplicationError(ErrorCodes.INTERNAL_SERVER_ERROR, reason.rawMessage);
}
- // data is trusted here, since it was scrubbed before on the server
- return new ApplicationError(code, reason.message, new TrustedValue(data));
+ return new ApplicationError(ErrorCodes.INTERNAL_SERVER_ERROR, reason.rawMessage);
}
toWorkspaceEnvironmentVariables(context: WorkspaceContext): WorkspaceEnvironmentVariable[] {
diff --git a/components/server/src/auth/errors.ts b/components/server/src/auth/errors.ts
index f517350e03330a..8017609e35dedf 100644
--- a/components/server/src/auth/errors.ts
+++ b/components/server/src/auth/errors.ts
@@ -4,21 +4,8 @@
* See License.AGPL.txt in the project root for license information.
*/
-import { Identity } from "@gitpod/gitpod-protocol";
import { SelectAccountPayload } from "@gitpod/gitpod-protocol/lib/auth";
-export interface TosNotAcceptedYetException extends Error {
- readonly identity: Identity;
-}
-export namespace TosNotAcceptedYetException {
- export function create(identity: Identity) {
- return Object.assign(new Error("TosNotAcceptedYetException"), { identity });
- }
- export function is(error: any): error is TosNotAcceptedYetException {
- return !!error && error.message === "TosNotAcceptedYetException";
- }
-}
-
export interface AuthException extends Error {
readonly payload: any;
readonly authException: string;
diff --git a/components/server/src/errors/index.ts b/components/server/src/errors/index.ts
index 793a15c3a6787b..9d85b7d1edbccc 100644
--- a/components/server/src/errors/index.ts
+++ b/components/server/src/errors/index.ts
@@ -5,62 +5,38 @@
*/
import { User, Token } from "@gitpod/gitpod-protocol";
+import {
+ RepositoryNotFoundError,
+ UnauthorizedRepositoryAccessError,
+} from "@gitpod/gitpod-protocol/lib/messaging/error";
-export interface NotFoundError extends Error {
- readonly data: NotFoundError.Data;
-}
export namespace NotFoundError {
- export interface Data {
- readonly host: string;
- readonly owner: string;
- readonly repoName: string;
- readonly userScopes?: string[];
- readonly lastUpdate?: string;
- }
export async function create(token: Token | undefined, user: User, host: string, owner: string, repoName: string) {
- const lastUpdate = token && token.updateDate;
+ const lastUpdate = (token && token.updateDate) || "";
const userScopes = token ? [...token.scopes] : [];
const userIsOwner = owner == user.name; // TODO: shouldn't this be a comparison with `identity.authName`?
- const data = { host, owner, repoName, userIsOwner, userScopes, lastUpdate };
- const error = Object.assign(new Error("NotFoundError"), { data });
- return error;
+ return new RepositoryNotFoundError({
+ host,
+ owner,
+ userIsOwner,
+ userScopes,
+ lastUpdate,
+ });
}
- export function is(error: any): error is NotFoundError {
- return (
- !!error &&
- !!error.data &&
- !!error.data.host &&
- !!error.data.owner &&
- !!error.data.repoName &&
- error.message === "NotFoundError"
- );
+ export function is(error: any): error is RepositoryNotFoundError {
+ return error instanceof RepositoryNotFoundError;
}
}
-export interface UnauthorizedError extends Error {
- readonly data: UnauthorizedError.Data;
-}
export namespace UnauthorizedError {
- export interface Data {
- readonly host: string;
- readonly scopes: string[];
- readonly messageHint: string;
- }
- const message = "UnauthorizedError";
export function create(host: string, scopes: string[], messageHint?: string) {
- const data = { host, scopes, messageHint: messageHint || "unauthorized" };
- const error = Object.assign(new Error(message), { data });
- return error;
+ return new UnauthorizedRepositoryAccessError({
+ host,
+ scopes,
+ });
}
- export function is(error: any): error is UnauthorizedError {
- return (
- !!error &&
- !!error.data &&
- !!error.data.host &&
- !!error.data.scopes &&
- !!error.data.messageHint &&
- error.message === message
- );
+ export function is(error: any): error is UnauthorizedRepositoryAccessError {
+ return error instanceof UnauthorizedRepositoryAccessError;
}
}
diff --git a/components/server/src/prebuilds/prebuild-manager.ts b/components/server/src/prebuilds/prebuild-manager.ts
index 4bf3de5402e465..563a0d1ad6a497 100644
--- a/components/server/src/prebuilds/prebuild-manager.ts
+++ b/components/server/src/prebuilds/prebuild-manager.ts
@@ -17,7 +17,6 @@ import {
User,
Workspace,
WorkspaceConfig,
- WorkspaceInstance,
} from "@gitpod/gitpod-protocol";
import { log } from "@gitpod/gitpod-protocol/lib/util/logging";
import { TraceContext } from "@gitpod/gitpod-protocol/lib/util/tracing";
@@ -42,12 +41,6 @@ import { generateAsyncGenerator } from "@gitpod/gitpod-protocol/lib/generate-asy
import { RedisSubscriber } from "../messaging/redis-subscriber";
import { ctxSignal } from "../util/request-context";
-export class WorkspaceRunningError extends Error {
- constructor(msg: string, public instance: WorkspaceInstance) {
- super(msg);
- }
-}
-
export interface StartPrebuildParams {
user: User;
context: CommitContext;
@@ -397,41 +390,6 @@ export class PrebuildManager {
}
}
- async retriggerPrebuild(
- ctx: TraceContext,
- user: User,
- project: Project | undefined,
- workspaceId: string,
- ): Promise {
- const span = TraceContext.startSpan("retriggerPrebuild", ctx);
- span.setTag("workspaceId", workspaceId);
- try {
- const workspacePromise = this.workspaceDB.trace({ span }).findById(workspaceId);
- const prebuildPromise = this.workspaceDB.trace({ span }).findPrebuildByWorkspaceID(workspaceId);
- const runningInstance = await this.workspaceDB.trace({ span }).findRunningInstance(workspaceId);
- if (runningInstance !== undefined) {
- throw new WorkspaceRunningError("Workspace is still runnning", runningInstance);
- }
- span.setTag("starting", true);
- const workspace = await workspacePromise;
- if (!workspace) {
- console.error("Unknown workspace id.", { workspaceId });
- throw new Error("Unknown workspace " + workspaceId);
- }
- const prebuild = await prebuildPromise;
- if (!prebuild) {
- throw new Error("No prebuild found for workspace " + workspaceId);
- }
- await this.workspaceService.startWorkspace({ span }, user, workspaceId, {}, false);
- return { prebuildId: prebuild.id, wsid: workspace.id, done: false };
- } catch (err) {
- TraceContext.setError({ span }, err);
- throw err;
- } finally {
- span.finish();
- }
- }
-
checkPrebuildPrecondition(params: { config: WorkspaceConfig; project: Project; context: CommitContext }): {
shouldRun: boolean;
reason: string;
diff --git a/components/server/src/workspace/config-provider.ts b/components/server/src/workspace/config-provider.ts
index abca87436630fd..141288ec528189 100644
--- a/components/server/src/workspace/config-provider.ts
+++ b/components/server/src/workspace/config-provider.ts
@@ -32,6 +32,7 @@ import { TraceContext } from "@gitpod/gitpod-protocol/lib/util/tracing";
import { Config } from "../config";
import { EntitlementService } from "../billing/entitlement-service";
import { TeamDB } from "@gitpod/gitpod-db/lib";
+import { InvalidGitpodYMLError } from "@gitpod/gitpod-protocol/lib/messaging/error";
const POD_PATH_WORKSPACE_BASE = "/workspace";
@@ -149,7 +150,9 @@ export class ConfigProvider {
customConfig = parseResult.config;
customConfig._origin = "additional-content";
if (parseResult.validationErrors) {
- const err = new InvalidGitpodYMLError(parseResult.validationErrors);
+ const err = new InvalidGitpodYMLError({
+ violations: parseResult.validationErrors,
+ });
// this is not a system error but a user misconfiguration
log.info(logContext, err.message, {
repoCloneUrl: commit.repository.cloneUrl,
@@ -186,7 +189,9 @@ export class ConfigProvider {
const parseResult = this.gitpodParser.parse(customConfigString);
customConfig = parseResult.config;
if (parseResult.validationErrors) {
- const err = new InvalidGitpodYMLError(parseResult.validationErrors);
+ const err = new InvalidGitpodYMLError({
+ violations: parseResult.validationErrors,
+ });
// this is not a system error but a user misconfiguration
log.info(logContext, err.message, {
repoCloneUrl: commit.repository.cloneUrl,
@@ -302,17 +307,3 @@ export class ConfigProvider {
return normalizedPath.includes("..") || pathSegments.slice(0, 2).join("/") != POD_PATH_WORKSPACE_BASE;
}
}
-
-export class InvalidGitpodYMLError extends Error {
- public readonly errorType = "invalidGitpodYML";
-
- constructor(public readonly validationErrors: string[]) {
- super("Invalid gitpod.yml: " + validationErrors.join(","));
- }
-}
-
-export namespace InvalidGitpodYMLError {
- export function is(obj: any): obj is InvalidGitpodYMLError {
- return "errorType" in obj && (obj as any).errorType === "invalidGitpodYML" && "validationErrors" in obj;
- }
-}
diff --git a/components/server/src/workspace/context-parser-service.ts b/components/server/src/workspace/context-parser-service.ts
index 8f51c4945643ad..c44aba962094ba 100644
--- a/components/server/src/workspace/context-parser-service.ts
+++ b/components/server/src/workspace/context-parser-service.ts
@@ -9,7 +9,8 @@ import { injectable, multiInject, inject } from "inversify";
import { HostContextProvider } from "../auth/host-context-provider";
import { IPrefixContextParser, IContextParser } from "./context-parser";
import { TraceContext } from "@gitpod/gitpod-protocol/lib/util/tracing";
-import { ConfigProvider, InvalidGitpodYMLError } from "./config-provider";
+import { ConfigProvider } from "./config-provider";
+import { InvalidGitpodYMLError } from "@gitpod/gitpod-protocol/lib/messaging/error";
@injectable()
export class ContextParser {
@@ -128,9 +129,9 @@ export class ContextParser {
config.config.mainConfiguration,
);
if (!CommitContext.is(mainRepoContext)) {
- throw new InvalidGitpodYMLError([
- `Cannot find main repository '${config.config.mainConfiguration}'.`,
- ]);
+ throw new InvalidGitpodYMLError({
+ violations: [`Cannot find main repository '${config.config.mainConfiguration}'.`],
+ });
}
// Note: we only care about repo related stuff in this function.
// Fields like `config.image` will not be exposed, so we don't pass organizationId here
@@ -146,7 +147,9 @@ export class ContextParser {
subRepo.url,
)) as CommitContext;
if (!CommitContext.is(subContext)) {
- throw new InvalidGitpodYMLError([`Cannot find sub-repository '${subRepo.url}'.`]);
+ throw new InvalidGitpodYMLError({
+ violations: [`Cannot find sub-repository '${subRepo.url}'.`],
+ });
}
if (context.repository.cloneUrl === subContext.repository.cloneUrl) {
// if it's the repo from the original context we want to use that commit.
diff --git a/components/server/src/workspace/gitpod-server-impl.ts b/components/server/src/workspace/gitpod-server-impl.ts
index e9370e3c06586a..bf44175740c29d 100644
--- a/components/server/src/workspace/gitpod-server-impl.ts
+++ b/components/server/src/workspace/gitpod-server-impl.ts
@@ -79,7 +79,11 @@ import {
AdminModifyRoleOrPermissionRequest,
WorkspaceAndInstance,
} from "@gitpod/gitpod-protocol/lib/admin-protocol";
-import { ApplicationError, ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error";
+import {
+ ApplicationError,
+ ErrorCodes,
+ UnauthorizedRepositoryAccessError,
+} from "@gitpod/gitpod-protocol/lib/messaging/error";
import { log, LogContext } from "@gitpod/gitpod-protocol/lib/util/logging";
import {
InterfaceWithTraceContext,
@@ -104,7 +108,6 @@ import { AuthProviderService } from "../auth/auth-provider-service";
import { HostContextProvider } from "../auth/host-context-provider";
import { GuardedResource, ResourceAccessGuard, ResourceAccessOp } from "../auth/resource-access";
import { Config } from "../config";
-import { NotFoundError, UnauthorizedError } from "../errors";
import { AuthorizationService } from "../user/authorization-service";
import { TokenProvider } from "../user/token-provider";
import { UserAuthentication } from "../user/user-authentication";
@@ -112,7 +115,7 @@ import { ContextParser } from "./context-parser-service";
import { GitTokenScopeGuesser } from "./git-token-scope-guesser";
import { isClusterMaintenanceError } from "./workspace-starter";
import { HeadlessLogUrls } from "@gitpod/gitpod-protocol/lib/headless-workspace-log";
-import { ConfigProvider, InvalidGitpodYMLError } from "./config-provider";
+import { ConfigProvider } from "./config-provider";
import { ProjectsService } from "../projects/projects-service";
import { IDEOptions } from "@gitpod/gitpod-protocol/lib/ide-protocol";
import {
@@ -1103,7 +1106,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
event: "snapshot_access_denied",
properties: { snapshot_id: context.snapshotId, error: String(error) },
}).catch((err) => log.error("cannot track event", err));
- if (UnauthorizedError.is(error)) {
+ if (error instanceof UnauthorizedRepositoryAccessError) {
throw error;
}
throw new ApplicationError(
@@ -1235,20 +1238,12 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
}
private handleError(error: any, logContext: LogContext, normalizedContextUrl: string) {
- if (NotFoundError.is(error)) {
- throw new ApplicationError(ErrorCodes.NOT_FOUND, "Repository not found.", error.data);
- }
- if (UnauthorizedError.is(error)) {
- throw new ApplicationError(ErrorCodes.NOT_AUTHENTICATED, "Unauthorized", error.data);
- }
- if (InvalidGitpodYMLError.is(error)) {
- throw new ApplicationError(ErrorCodes.INVALID_GITPOD_YML, error.message);
- }
-
if (ApplicationError.hasErrorCode(error)) {
// specific errors will be handled in create-workspace.tsx
throw error;
}
+ // TODO(ak) not sure about it we shovel all errors in context parsing error
+ // we should rather do internal errors, and categorize at sources
log.debug(logContext, error);
throw new ApplicationError(
ErrorCodes.CONTEXT_PARSE_ERROR,
@@ -2140,21 +2135,11 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
const user = await this.checkAndBlockUser("getProjectOverview");
await this.guardProjectOperation(user, projectId, "get");
- try {
- const result = await this.projectsService.getProjectOverview(user, projectId);
- if (result) {
- result.isConsideredInactive = await this.projectsService.isProjectConsideredInactive(
- user.id,
- projectId,
- );
- }
- return result;
- } catch (error) {
- if (UnauthorizedError.is(error)) {
- throw new ApplicationError(ErrorCodes.NOT_AUTHENTICATED, "Unauthorized", error.data);
- }
- throw error;
+ const result = await this.projectsService.getProjectOverview(user, projectId);
+ if (result) {
+ result.isConsideredInactive = await this.projectsService.isProjectConsideredInactive(user.id, projectId);
}
+ return result;
}
async adminFindPrebuilds(ctx: TraceContext, params: FindPrebuildsParams): Promise {