Skip to content

Commit

Permalink
Show more semantic errors for project-less prebuild requests
Browse files Browse the repository at this point in the history
  • Loading branch information
jankeromnes committed Nov 30, 2022
1 parent 16e60d6 commit ddd7a0d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
10 changes: 10 additions & 0 deletions components/dashboard/src/start/CreateWorkspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,16 @@ export default class CreateWorkspace extends React.Component<CreateWorkspaceProp
phase = StartPhase.Stopped;
statusMessage = <UsageLimitReachedModal hints={this.state?.error?.data} />;
break;
case ErrorCodes.PROJECT_REQUIRED:
statusMessage = (
<p className="text-base text-gitpod-red w-96">
{JSON.stringify(this.state?.error, null, 2)}
<a className="gp-link" href="https://www.gitpod.io/docs/configure/projects">
Learn more
</a>
</p>
);
break;
default:
statusMessage = (
<p className="text-base text-gitpod-red w-96">
Expand Down
3 changes: 3 additions & 0 deletions components/gitpod-protocol/src/messaging/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export namespace ErrorCodes {
// 430 Repository not whitelisted (custom status code)
export const REPOSITORY_NOT_WHITELISTED = 430;

// 440 Prebuilds now always require a project (custom status code)
export const PROJECT_REQUIRED = 440;

// 450 Payment error
export const PAYMENT_ERROR = 450;

Expand Down
7 changes: 5 additions & 2 deletions components/server/ee/src/prebuilds/prebuild-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import { StopWorkspacePolicy } from "@gitpod/ws-manager/lib";
import { error } from "console";
import { IncrementalPrebuildsService } from "./incremental-prebuilds-service";
import { PrebuildRateLimiterConfig } from "../../../src/workspace/prebuild-rate-limiter";
import { ResponseError } from "vscode-ws-jsonrpc";
import { ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error";

export class WorkspaceRunningError extends Error {
constructor(msg: string, public instance: WorkspaceInstance) {
Expand Down Expand Up @@ -124,10 +126,11 @@ export class PrebuildManager {

try {
if (user.blocked) {
throw new Error(`Blocked users cannot start prebuilds (${user.name})`);
throw new ResponseError(ErrorCodes.USER_BLOCKED, `Blocked users cannot start prebuilds (${user.name})`);
}
if (!project) {
throw new Error(
throw new ResponseError(
ErrorCodes.PROJECT_REQUIRED,
`Running prebuilds without a project is no longer supported. Please add '${cloneURL}' as a project in a Gitpod team.`,
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
*/

import { User, WorkspaceContext, ContextURL } from "@gitpod/gitpod-protocol";
import { ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error";
import { injectable } from "inversify";
import { ResponseError } from "vscode-ws-jsonrpc";
import { IPrefixContextParser } from "../../../src/workspace/context-parser";

@injectable()
Expand All @@ -19,7 +21,8 @@ export class StartPrebuildContextParser implements IPrefixContextParser {
}

public async handle(user: User, prefix: string, context: WorkspaceContext): Promise<WorkspaceContext> {
throw new Error(
throw new ResponseError(
ErrorCodes.PROJECT_REQUIRED,
`Running prebuilds without a project is no longer supported. Please add your repository as a project in a Gitpod team.`,
);
}
Expand Down

0 comments on commit ddd7a0d

Please sign in to comment.