[codex] structure source-control repository failures (#3336)

Co-authored-by: codex <[email protected]>
This commit is contained in:
Julius Marmingeandcodex authored and GitHub committed 2026-06-20 15:56:46 -07:00
1 parent 6ff6c13fc8
commit a26f0dc89f
2 files changed
+98 -45

No files matched your search

@@ -39,41 +39,14 @@ export class SourceControlRepositoryService extends Context.Service<
}
>()("t3/sourceControl/SourceControlRepositoryService") {}
function detailFromUnknown(cause: unknown): string {
if (typeof cause === "object" && cause !== null) {
if ("detail" in cause && typeof cause.detail === "string" && cause.detail.length > 0) {
return cause.detail;
}
if ("message" in cause && typeof cause.message === "string" && cause.message.length > 0) {
return cause.message;
}
}
return "An unexpected source control error occurred.";
}
function repositoryError(input: {
readonly operation: string;
readonly provider: SourceControlProviderKind;
readonly detail: string;
readonly cause?: unknown;
}): SourceControlRepositoryError {
return new SourceControlRepositoryError({
provider: input.provider,
operation: input.operation,
detail: input.detail,
...(input.cause === undefined ? {} : { cause: input.cause }),
});
}
function mapRepositoryError(operation: string, provider: SourceControlProviderKind) {
return Effect.mapError((cause: unknown) =>
isSourceControlRepositoryError(cause)
? cause
: repositoryError({
: new SourceControlRepositoryError({
operation,
provider,
detail: detailFromUnknown(cause),
detail: "The source control operation could not be completed.",
cause,
}),
);
@@ -130,7 +103,7 @@ export const make = Effect.gen(function* () {
}
return Effect.fail(
repositoryError({
new SourceControlRepositoryError({
operation: input.operation,
provider: input.provider,
detail: "Choose a source control provider before continuing.",
@@ -157,7 +130,7 @@ export const make = Effect.gen(function* () {
function* (destinationPath: string) {
const trimmed = destinationPath.trim();
if (trimmed.length === 0) {
return yield* repositoryError({
return yield* new SourceControlRepositoryError({
operation: "cloneRepository",
provider: "unknown",
detail: "Choose a destination path before cloning.",
@@ -171,21 +144,22 @@ export const make = Effect.gen(function* () {
const prepareDestination = Effect.fn("SourceControlRepositoryService.prepareDestination")(
function* (destinationPath: string) {
const normalizedDestination = yield* normalizeDestinationPath(destinationPath);
if (yield* fileSystem.exists(normalizedDestination).pipe(Effect.orElseSucceed(() => false))) {
if (yield* fileSystem.exists(normalizedDestination)) {
const entries = yield* fileSystem
.readDirectory(normalizedDestination, { recursive: false })
.pipe(
Effect.mapError((cause) =>
repositoryError({
operation: "cloneRepository",
provider: "unknown",
detail: "Destination path already exists and is not a directory.",
cause,
}),
Effect.mapError(
(cause) =>
new SourceControlRepositoryError({
operation: "cloneRepository",
provider: "unknown",
detail: "Destination path already exists and is not a directory.",
cause,
}),
),
);
if (entries.length > 0) {
return yield* repositoryError({
return yield* new SourceControlRepositoryError({
operation: "cloneRepository",
provider: "unknown",
detail: "Destination path already exists and is not empty.",
@@ -222,7 +196,7 @@ export const make = Effect.gen(function* () {
}
if (!remoteUrl) {
return yield* repositoryError({
return yield* new SourceControlRepositoryError({
operation: "cloneRepository",
provider,
detail: "Enter a repository path or clone URL before cloning.",