Showing the changes to apps/server/src/workspace/WorkspaceFileSystem.ts (1 of 2 files). Show all
Unified · Split
| @@ -131,20 +131,22 @@ export const make = Effect.gen(function* () { · 130 unmodified lines | ||
| 131 | 131 | const workspacePaths = yield* WorkspacePaths.WorkspacePaths; |
| 132 | 132 | const workspaceEntries = yield* WorkspaceEntries.WorkspaceEntries; |
| 133 | 133 | |
| 134 | − const operationError = ( | |
| 135 | − input: ProjectReadFileInput | ProjectWriteFileInput, | |
| 136 | − resolvedPath: string, | |
| 137 | − operationPath: string, | |
| 138 | − operation: WorkspaceFileSystemOperationError["operation"], | |
| 139 | − ) => (cause: unknown) => | |
| 140 | − new WorkspaceFileSystemOperationError({ | |
| 141 | − workspaceRoot: input.cwd, | |
| 142 | − relativePath: input.relativePath, | |
| 143 | − resolvedPath, | |
| 144 | − operationPath, | |
| 145 | − operation, | |
| 146 | − cause, | |
| 147 | − }); | |
| 134 | + const operationError = | |
| 135 | + ( | |
| 136 | + input: ProjectReadFileInput | ProjectWriteFileInput, | |
| 137 | + resolvedPath: string, | |
| 138 | + operationPath: string, | |
| 139 | + operation: WorkspaceFileSystemOperationError["operation"], | |
| 140 | + ) => | |
| 141 | + (cause: unknown) => | |
| 142 | + new WorkspaceFileSystemOperationError({ | |
| 143 | + workspaceRoot: input.cwd, | |
| 144 | + relativePath: input.relativePath, | |
| 145 | + resolvedPath, | |
| 146 | + operationPath, | |
| 147 | + operation, | |
| 148 | + cause, | |
| 149 | + }); | |
| 148 | 150 | |
| 149 | 151 | const readFile: WorkspaceFileSystem["Service"]["readFile"] = Effect.fn( |
| 150 | 152 | "WorkspaceFileSystem.readFile", |
| @@ -203,10 +205,12 @@ export const make = Effect.gen(function* () { · 52 unmodified lines | ||
| 203 | 205 | const fileBytes = |
| 204 | 206 | bytesToRead === 0 |
| 205 | 207 | ? new Uint8Array() |
| 206 | − : yield* file.readAlloc(bytesToRead).pipe( | |
| 207 | − Effect.map(Option.getOrElse(() => new Uint8Array())), | |
| 208 | − Effect.mapError(operationError(input, realTargetPath, realTargetPath, "read")), | |
| 209 | − ); | |
| 208 | + : yield* file | |
| 209 | + .readAlloc(bytesToRead) | |
| 210 | + .pipe( | |
| 211 | + Effect.map(Option.getOrElse(() => new Uint8Array())), | |
| 212 | + Effect.mapError(operationError(input, realTargetPath, realTargetPath, "read")), | |
| 213 | + ); | |
| 210 | 214 | if (fileBytes.includes(0)) { |
| 211 | 215 | return yield* new WorkspaceBinaryFileError({ |
| 212 | 216 | workspaceRoot: input.cwd, |
| @@ -237,12 +241,21 @@ export const make = Effect.gen(function* () { · 24 unmodified lines | ||
| 237 | 241 | .makeDirectory(path.dirname(target.absolutePath), { recursive: true }) |
| 238 | 242 | .pipe( |
| 239 | 243 | Effect.mapError( |
| 240 | − operationError(input, target.absolutePath, path.dirname(target.absolutePath), "make-directory"), | |
| 244 | + operationError( | |
| 245 | + input, | |
| 246 | + target.absolutePath, | |
| 247 | + path.dirname(target.absolutePath), | |
| 248 | + "make-directory", | |
| 249 | + ), | |
| 250 | + ), | |
| 251 | + ); | |
| 252 | + yield* fileSystem | |
| 253 | + .writeFileString(target.absolutePath, input.contents) | |
| 254 | + .pipe( | |
| 255 | + Effect.mapError( | |
| 256 | + operationError(input, target.absolutePath, target.absolutePath, "write-file"), | |
| 241 | 257 | ), |
| 242 | 258 | ); |
| 243 | − yield* fileSystem.writeFileString(target.absolutePath, input.contents).pipe( | |
| 244 | − Effect.mapError(operationError(input, target.absolutePath, target.absolutePath, "write-file")), | |
| 245 | − ); | |
| 246 | 259 | yield* workspaceEntries.refresh(input.cwd); |
| 247 | 260 | return { relativePath: target.relativePath }; |
| 248 | 261 | }); |