History

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

Julius Marminge committed 4 months ago

Commit a26f0dc1 parent 6ff6c132 files · +98 −45Browse files

Showing the changes to apps/server/src/sourceControl/SourceControlRepositoryService.ts (1 of 2 files). Show all

Unified · Split

apps/server/src/sourceControl/SourceControlRepositoryService.ts+15−41
@@ -39,41 +39,14 @@ export class SourceControlRepositoryService extends Context.Service< · 38 unmodified lines
3939 }
4040 >()("t3/sourceControl/SourceControlRepositoryService") {}
4141
42−function detailFromUnknown(cause: unknown): string {
43− if (typeof cause === "object" && cause !== null) {
44− if ("detail" in cause && typeof cause.detail === "string" && cause.detail.length > 0) {
45− return cause.detail;
46− }
47− if ("message" in cause && typeof cause.message === "string" && cause.message.length > 0) {
48− return cause.message;
49− }
50− }
51−
52− return "An unexpected source control error occurred.";
53−}
54−
55−function repositoryError(input: {
56− readonly operation: string;
57− readonly provider: SourceControlProviderKind;
58− readonly detail: string;
59− readonly cause?: unknown;
60−}): SourceControlRepositoryError {
61− return new SourceControlRepositoryError({
62− provider: input.provider,
63− operation: input.operation,
64− detail: input.detail,
65− ...(input.cause === undefined ? {} : { cause: input.cause }),
66− });
67−}
68−
6942 function mapRepositoryError(operation: string, provider: SourceControlProviderKind) {
7043 return Effect.mapError((cause: unknown) =>
7144 isSourceControlRepositoryError(cause)
7245 ? cause
73− : repositoryError({
46+ : new SourceControlRepositoryError({
7447 operation,
7548 provider,
76− detail: detailFromUnknown(cause),
49+ detail: "The source control operation could not be completed.",
7750 cause,
7851 }),
7952 );
@@ -130,7 +103,7 @@ export const make = Effect.gen(function* () { · 50 unmodified lines
130103 }
131104
132105 return Effect.fail(
133− repositoryError({
106+ new SourceControlRepositoryError({
134107 operation: input.operation,
135108 provider: input.provider,
136109 detail: "Choose a source control provider before continuing.",
@@ -157,7 +130,7 @@ export const make = Effect.gen(function* () { · 20 unmodified lines
157130 function* (destinationPath: string) {
158131 const trimmed = destinationPath.trim();
159132 if (trimmed.length === 0) {
160− return yield* repositoryError({
133+ return yield* new SourceControlRepositoryError({
161134 operation: "cloneRepository",
162135 provider: "unknown",
163136 detail: "Choose a destination path before cloning.",
@@ -171,21 +144,22 @@ export const make = Effect.gen(function* () { · 7 unmodified lines
171144 const prepareDestination = Effect.fn("SourceControlRepositoryService.prepareDestination")(
172145 function* (destinationPath: string) {
173146 const normalizedDestination = yield* normalizeDestinationPath(destinationPath);
174− if (yield* fileSystem.exists(normalizedDestination).pipe(Effect.orElseSucceed(() => false))) {
147+ if (yield* fileSystem.exists(normalizedDestination)) {
175148 const entries = yield* fileSystem
176149 .readDirectory(normalizedDestination, { recursive: false })
177150 .pipe(
178− Effect.mapError((cause) =>
179− repositoryError({
180− operation: "cloneRepository",
181− provider: "unknown",
182− detail: "Destination path already exists and is not a directory.",
183− cause,
184− }),
151+ Effect.mapError(
152+ (cause) =>
153+ new SourceControlRepositoryError({
154+ operation: "cloneRepository",
155+ provider: "unknown",
156+ detail: "Destination path already exists and is not a directory.",
157+ cause,
158+ }),
185159 ),
186160 );
187161 if (entries.length > 0) {
188− return yield* repositoryError({
162+ return yield* new SourceControlRepositoryError({
189163 operation: "cloneRepository",
190164 provider: "unknown",
191165 detail: "Destination path already exists and is not empty.",
@@ -222,7 +196,7 @@ export const make = Effect.gen(function* () { · 30 unmodified lines
222196 }
223197
224198 if (!remoteUrl) {
225− return yield* repositoryError({
199+ return yield* new SourceControlRepositoryError({
226200 operation: "cloneRepository",
227201 provider,
228202 detail: "Enter a repository path or clone URL before cloning.",