Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ it.effect("includes the request cwd when an unregistered provider is used", () =
assert.strictEqual(error.operation, "getChangeRequest");
assert.strictEqual(error.cwd, "/repo");
assert.strictEqual(error.reference, "#42");
assert.strictEqual(error.detail, "No source control provider was detected for this project.");
assert.strictEqual(
error.message,
"Source control getChangeRequest failed: No source control provider was detected for this project.",
);
}),
);

Expand Down
20 changes: 13 additions & 7 deletions apps/server/src/sourceControl/SourceControlProviderRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ export class SourceControlProviderRegistry extends Context.Service<
}
>()("t3/sourceControl/SourceControlProviderRegistry") {}

function unsupportedProviderDetail(kind: SourceControlProviderKind): string {
return kind === "unknown"
? "No source control provider was detected for this project."
: `No ${kind} source control provider is registered.`;
Comment thread
Guria marked this conversation as resolved.
}

function unsupportedProvider(
kind: SourceControlProviderKind,
): SourceControlProvider.SourceControlProvider["Service"] {
Expand All @@ -74,54 +80,54 @@ function unsupportedProvider(
provider: kind,
operation: "listChangeRequests",
cwd: input.cwd,
detail: `No ${kind} source control provider is registered.`,
detail: unsupportedProviderDetail(kind),
}),
getChangeRequest: (input) =>
new SourceControlProviderError({
provider: kind,
operation: "getChangeRequest",
cwd: input.cwd,
reference: SourceControlProvider.transportSafeSourceControlErrorValue(input.reference),
detail: `No ${kind} source control provider is registered.`,
detail: unsupportedProviderDetail(kind),
}),
createChangeRequest: (input) =>
new SourceControlProviderError({
provider: kind,
operation: "createChangeRequest",
cwd: input.cwd,
reference: SourceControlProvider.transportSafeSourceControlErrorValue(input.headSelector),
detail: `No ${kind} source control provider is registered.`,
detail: unsupportedProviderDetail(kind),
}),
getRepositoryCloneUrls: (input) =>
new SourceControlProviderError({
provider: kind,
operation: "getRepositoryCloneUrls",
cwd: input.cwd,
repository: SourceControlProvider.transportSafeSourceControlErrorValue(input.repository),
detail: `No ${kind} source control provider is registered.`,
detail: unsupportedProviderDetail(kind),
}),
createRepository: (input) =>
new SourceControlProviderError({
provider: kind,
operation: "createRepository",
cwd: input.cwd,
repository: SourceControlProvider.transportSafeSourceControlErrorValue(input.repository),
detail: `No ${kind} source control provider is registered.`,
detail: unsupportedProviderDetail(kind),
}),
getDefaultBranch: (input) =>
new SourceControlProviderError({
provider: kind,
operation: "getDefaultBranch",
cwd: input.cwd,
detail: `No ${kind} source control provider is registered.`,
detail: unsupportedProviderDetail(kind),
}),
checkoutChangeRequest: (input) =>
new SourceControlProviderError({
provider: kind,
operation: "checkoutChangeRequest",
cwd: input.cwd,
reference: SourceControlProvider.transportSafeSourceControlErrorValue(input.reference),
detail: `No ${kind} source control provider is registered.`,
detail: unsupportedProviderDetail(kind),
}),
});
}
Expand Down
4 changes: 3 additions & 1 deletion packages/contracts/src/sourceControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ export class SourceControlProviderError extends Schema.TaggedError<SourceControl
},
) {
override get message(): string {
return `Source control provider ${this.provider} failed in ${this.operation}: ${this.detail}`;
return this.provider === "unknown"
? `Source control ${this.operation} failed: ${this.detail}`
: `Source control provider ${this.provider} failed in ${this.operation}: ${this.detail}`;
}
}

Expand Down
Loading