Showing the changes to apps/server/src/sourceControl/SourceControlRepositoryService.ts (1 of 2 files). Show all
Unified · Split
| @@ -39,41 +39,14 @@ export class SourceControlRepositoryService extends Context.Service< · 38 unmodified lines | ||
| 39 | 39 | } |
| 40 | 40 | >()("t3/sourceControl/SourceControlRepositoryService") {} |
| 41 | 41 | |
| 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 | − | |
| 69 | 42 | function mapRepositoryError(operation: string, provider: SourceControlProviderKind) { |
| 70 | 43 | return Effect.mapError((cause: unknown) => |
| 71 | 44 | isSourceControlRepositoryError(cause) |
| 72 | 45 | ? cause |
| 73 | − : repositoryError({ | |
| 46 | + : new SourceControlRepositoryError({ | |
| 74 | 47 | operation, |
| 75 | 48 | provider, |
| 76 | − detail: detailFromUnknown(cause), | |
| 49 | + detail: "The source control operation could not be completed.", | |
| 77 | 50 | cause, |
| 78 | 51 | }), |
| 79 | 52 | ); |
| @@ -130,7 +103,7 @@ export const make = Effect.gen(function* () { · 50 unmodified lines | ||
| 130 | 103 | } |
| 131 | 104 | |
| 132 | 105 | return Effect.fail( |
| 133 | − repositoryError({ | |
| 106 | + new SourceControlRepositoryError({ | |
| 134 | 107 | operation: input.operation, |
| 135 | 108 | provider: input.provider, |
| 136 | 109 | detail: "Choose a source control provider before continuing.", |
| @@ -157,7 +130,7 @@ export const make = Effect.gen(function* () { · 20 unmodified lines | ||
| 157 | 130 | function* (destinationPath: string) { |
| 158 | 131 | const trimmed = destinationPath.trim(); |
| 159 | 132 | if (trimmed.length === 0) { |
| 160 | − return yield* repositoryError({ | |
| 133 | + return yield* new SourceControlRepositoryError({ | |
| 161 | 134 | operation: "cloneRepository", |
| 162 | 135 | provider: "unknown", |
| 163 | 136 | detail: "Choose a destination path before cloning.", |
| @@ -171,21 +144,22 @@ export const make = Effect.gen(function* () { · 7 unmodified lines | ||
| 171 | 144 | const prepareDestination = Effect.fn("SourceControlRepositoryService.prepareDestination")( |
| 172 | 145 | function* (destinationPath: string) { |
| 173 | 146 | const normalizedDestination = yield* normalizeDestinationPath(destinationPath); |
| 174 | − if (yield* fileSystem.exists(normalizedDestination).pipe(Effect.orElseSucceed(() => false))) { | |
| 147 | + if (yield* fileSystem.exists(normalizedDestination)) { | |
| 175 | 148 | const entries = yield* fileSystem |
| 176 | 149 | .readDirectory(normalizedDestination, { recursive: false }) |
| 177 | 150 | .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 | + }), | |
| 185 | 159 | ), |
| 186 | 160 | ); |
| 187 | 161 | if (entries.length > 0) { |
| 188 | − return yield* repositoryError({ | |
| 162 | + return yield* new SourceControlRepositoryError({ | |
| 189 | 163 | operation: "cloneRepository", |
| 190 | 164 | provider: "unknown", |
| 191 | 165 | detail: "Destination path already exists and is not empty.", |
| @@ -222,7 +196,7 @@ export const make = Effect.gen(function* () { · 30 unmodified lines | ||
| 222 | 196 | } |
| 223 | 197 | |
| 224 | 198 | if (!remoteUrl) { |
| 225 | − return yield* repositoryError({ | |
| 199 | + return yield* new SourceControlRepositoryError({ | |
| 226 | 200 | operation: "cloneRepository", |
| 227 | 201 | provider, |
| 228 | 202 | detail: "Enter a repository path or clone URL before cloning.", |