Skip to content

Commit fbcde24

Browse files
committed
Gently soft-fail when the Dockerfile isn't found
1 parent 13cf10a commit fbcde24

File tree

8 files changed

+50
-33
lines changed

8 files changed

+50
-33
lines changed

components/server/src/azure-devops/azure-file-provider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import { injectable, inject } from "inversify";
88

9-
import { FileProvider, MaybeContent } from "../repohost/file-provider";
9+
import { FileProvider, MaybeContent, RevisionNotFoundError } from "../repohost/file-provider";
1010
import { Commit, User, Repository } from "@gitpod/gitpod-protocol";
1111
import { AzureDevOpsApi } from "./azure-api";
1212
import { log } from "@gitpod/gitpod-protocol/lib/util/logging";
@@ -34,7 +34,7 @@ export class AzureDevOpsFileProvider implements FileProvider {
3434
): Promise<string> {
3535
const [azOrgId, azProject] = getOrgAndProject(repository.owner);
3636
const repoName = repository.name;
37-
const notFoundError = new Error(
37+
const notFoundError = new RevisionNotFoundError(
3838
`File ${path} does not exist in repository ${repository.owner}/${repository.name}`,
3939
);
4040
const fileExists =

components/server/src/bitbucket-server/bitbucket-server-file-provider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import { Commit, Repository, User } from "@gitpod/gitpod-protocol";
88
import { inject, injectable } from "inversify";
9-
import { FileProvider, MaybeContent } from "../repohost/file-provider";
9+
import { FileProvider, MaybeContent, RevisionNotFoundError } from "../repohost/file-provider";
1010
import { BitbucketServerApi } from "./bitbucket-server-api";
1111

1212
@injectable()
@@ -27,7 +27,7 @@ export class BitbucketServerFileProvider implements FileProvider {
2727
if (!repoKind) {
2828
throw new Error("Repo kind is missing.");
2929
}
30-
const notFoundError = new Error(
30+
const notFoundError = new RevisionNotFoundError(
3131
`File ${path} does not exist in repository ${repository.owner}/${repository.name}`,
3232
);
3333

components/server/src/bitbucket/bitbucket-file-provider.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import { Commit, Repository, User } from "@gitpod/gitpod-protocol";
88
import { log } from "@gitpod/gitpod-protocol/lib/util/logging";
99
import { inject, injectable } from "inversify";
10-
import { FileProvider, MaybeContent } from "../repohost/file-provider";
10+
import { FileProvider, MaybeContent, RevisionNotFoundError } from "../repohost/file-provider";
1111
import { BitbucketApiFactory } from "./bitbucket-api-factory";
1212

1313
@injectable()
@@ -48,7 +48,9 @@ export class BitbucketFileProvider implements FileProvider {
4848
return lastCommit;
4949
} catch (err) {
5050
if (err.status && err.status === 404) {
51-
throw new Error(`File ${path} does not exist in repository ${repository.owner}/${repository.name}`);
51+
throw new RevisionNotFoundError(
52+
`File ${path} does not exist in repository ${repository.owner}/${repository.name}`,
53+
);
5254
}
5355

5456
log.error({ userId: user.id }, err);

components/server/src/github/file-provider.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import { injectable, inject } from "inversify";
88

9-
import { FileProvider, MaybeContent } from "../repohost/file-provider";
9+
import { FileProvider, MaybeContent, RevisionNotFoundError } from "../repohost/file-provider";
1010
import { Commit, User, Repository } from "@gitpod/gitpod-protocol";
1111
import { GitHubRestApi } from "./api";
1212
import { log } from "@gitpod/gitpod-protocol/lib/util/logging";
@@ -29,14 +29,14 @@ export class GithubFileProvider implements FileProvider {
2929
user: User,
3030
path: string,
3131
): Promise<string> {
32-
const notFoundError = new Error(
32+
const notFoundError = new RevisionNotFoundError(
3333
`File ${path} does not exist in repository ${repository.owner}/${repository.name}`,
3434
);
35-
// const fileExists =
36-
// (await this.getFileContent({ repository, revision: revisionOrBranch }, user, path)) !== undefined;
37-
// if (!fileExists) {
38-
// throw notFoundError;
39-
// }
35+
const fileExists =
36+
(await this.getFileContent({ repository, revision: revisionOrBranch }, user, path)) !== undefined;
37+
if (!fileExists) {
38+
throw notFoundError;
39+
}
4040

4141
const commits = (
4242
await this.githubApi.run(user, (gh) =>

components/server/src/gitlab/file-provider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import { injectable, inject } from "inversify";
88

9-
import { FileProvider, MaybeContent } from "../repohost/file-provider";
9+
import { FileProvider, MaybeContent, RevisionNotFoundError } from "../repohost/file-provider";
1010
import { Commit, User, Repository } from "@gitpod/gitpod-protocol";
1111
import { GitLabApi, GitLab } from "./api";
1212
import { log } from "@gitpod/gitpod-protocol/lib/util/logging";
@@ -29,7 +29,7 @@ export class GitlabFileProvider implements FileProvider {
2929
user: User,
3030
path: string,
3131
): Promise<string> {
32-
const notFoundError = new Error(
32+
const notFoundError = new RevisionNotFoundError(
3333
`File ${path} does not exist in repository ${repository.owner}/${repository.name}`,
3434
);
3535

components/server/src/repohost/file-provider.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ import { User, Repository, Commit } from "@gitpod/gitpod-protocol";
88

99
export type MaybeContent = string | undefined;
1010

11+
export class RevisionNotFoundError extends Error {
12+
constructor(message: string) {
13+
super(message);
14+
this.name = "RevisionNotFoundError";
15+
}
16+
}
17+
1118
export const FileProvider = Symbol("FileProvider");
1219
export interface FileProvider {
1320
getGitpodFileContent(commit: Commit, user: User): Promise<MaybeContent>;

components/server/src/workspace/config-provider.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { Config } from "../config";
3333
import { EntitlementService } from "../billing/entitlement-service";
3434
import { TeamDB } from "@gitpod/gitpod-db/lib";
3535
import { InvalidGitpodYMLError } from "@gitpod/public-api-common/lib/public-api-errors";
36+
import { RevisionNotFoundError } from "../repohost";
3637

3738
const POD_PATH_WORKSPACE_BASE = "/workspace";
3839

@@ -258,12 +259,14 @@ export class ConfigProvider {
258259
throw new Error(`Cannot fetch workspace image source for host: ${host}`);
259260
}
260261
const repoHost = hostContext.services;
261-
const lastDockerFileSha = await repoHost.fileProvider.getLastChangeRevision(
262-
repository,
263-
revisionOrTagOrBranch,
264-
user,
265-
dockerFilePath,
266-
);
262+
const lastDockerFileSha = await repoHost.fileProvider
263+
.getLastChangeRevision(repository, revisionOrTagOrBranch, user, dockerFilePath)
264+
.catch((e) => {
265+
if (e instanceof RevisionNotFoundError) {
266+
return "";
267+
}
268+
throw e;
269+
});
267270
return {
268271
repository,
269272
revision: lastDockerFileSha,

components/server/src/workspace/image-source-provider.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
AdditionalContentContext,
2020
} from "@gitpod/gitpod-protocol";
2121
import { createHash } from "crypto";
22+
import { RevisionNotFoundError } from "../repohost";
2223

2324
@injectable()
2425
export class ImageSourceProvider {
@@ -43,12 +44,14 @@ export class ImageSourceProvider {
4344
if (!hostContext || !hostContext.services) {
4445
throw new Error(`Cannot fetch workspace image source for host: ${repository.host}`);
4546
}
46-
const lastDockerFileSha = await hostContext.services.fileProvider.getLastChangeRevision(
47-
repository,
48-
imgcfg.externalSource.revision,
49-
user,
50-
imgcfg.file,
51-
);
47+
const lastDockerFileSha = await hostContext.services.fileProvider
48+
.getLastChangeRevision(repository, imgcfg.externalSource.revision, user, imgcfg.file)
49+
.catch((e) => {
50+
if (e instanceof RevisionNotFoundError) {
51+
return "";
52+
}
53+
throw e;
54+
});
5255
result = <WorkspaceImageSourceDocker>{
5356
dockerFilePath: imgcfg.file,
5457
dockerFileSource: imgcfg.externalSource,
@@ -72,12 +75,14 @@ export class ImageSourceProvider {
7275
if (!hostContext || !hostContext.services) {
7376
throw new Error(`Cannot fetch workspace image source for host: ${context.repository.host}`);
7477
}
75-
const lastDockerFileSha = await hostContext.services.fileProvider.getLastChangeRevision(
76-
context.repository,
77-
context.revision,
78-
user,
79-
imgcfg.file,
80-
);
78+
const lastDockerFileSha = await hostContext.services.fileProvider
79+
.getLastChangeRevision(context.repository, context.revision, user, imgcfg.file)
80+
.catch((e) => {
81+
if (e instanceof RevisionNotFoundError) {
82+
return "";
83+
}
84+
throw e;
85+
});
8186
result = <WorkspaceImageSourceDocker>{
8287
dockerFilePath: imgcfg.file,
8388
dockerFileSource: context,

0 commit comments

Comments
 (0)