History

Yield tagged workspace read errors directly

Cursor Agent committed 4 months ago

Commit 201f6541 parent 7f891481 file · +16 −22Browse files

Showing the changes to apps/server/src/workspace/WorkspaceFileSystem.ts (1 of 1 file). Show all

Unified · Split

apps/server/src/workspace/WorkspaceFileSystem.ts+16−22
@@ -135,26 +135,22 @@ export const make = Effect.gen(function* () { · 134 unmodified lines
135 relativeRealPath === ".." ||135 relativeRealPath === ".." ||
136 path.isAbsolute(relativeRealPath)136 path.isAbsolute(relativeRealPath)
137 ) {137 ) {
138 return yield* Effect.fail(138 return yield* new WorkspaceReadFileResolvedOutsideRootError({
139 new WorkspaceReadFileResolvedOutsideRootError({139 cwd: input.cwd,
140 cwd: input.cwd,140 relativePath: target.relativePath,
141 relativePath: target.relativePath,141 realWorkspaceRoot,
142 realWorkspaceRoot,142 realTargetPath,
143 realTargetPath,143 });
144 }),
145 );
146 }144 }
147 145
148 const handle = yield* fileSystem.open(realTargetPath, { flag: "r" });146 const handle = yield* fileSystem.open(realTargetPath, { flag: "r" });
149 const stat = yield* handle.stat;147 const stat = yield* handle.stat;
150 if (stat.type !== "File") {148 if (stat.type !== "File") {
151 return yield* Effect.fail(149 return yield* new WorkspaceReadFileNotFileError({
152 new WorkspaceReadFileNotFileError({150 cwd: input.cwd,
153 cwd: input.cwd,151 relativePath: target.relativePath,
154 relativePath: target.relativePath,152 fileType: stat.type,
155 fileType: stat.type,153 });
156 }),
157 );
158 }154 }
159 const byteLength = Number(stat.size);155 const byteLength = Number(stat.size);
160 const bytesToRead = Math.min(byteLength, PROJECT_READ_FILE_MAX_BYTES);156 const bytesToRead = Math.min(byteLength, PROJECT_READ_FILE_MAX_BYTES);
@@ -163,13 +159,11 @@ export const make = Effect.gen(function* () { · 2 unmodified lines
163 const fileBytes = buffer.subarray(0, Number(bytesRead));159 const fileBytes = buffer.subarray(0, Number(bytesRead));
164 const nulByteOffset = fileBytes.indexOf(0);160 const nulByteOffset = fileBytes.indexOf(0);
165 if (nulByteOffset !== -1) {161 if (nulByteOffset !== -1) {
166 return yield* Effect.fail(162 return yield* new WorkspaceReadFileBinaryFileError({
167 new WorkspaceReadFileBinaryFileError({163 cwd: input.cwd,
168 cwd: input.cwd,164 relativePath: target.relativePath,
169 relativePath: target.relativePath,165 nulByteOffset,
170 nulByteOffset,166 });
171 }),
172 );
173 }167 }
174 const contents = new TextDecoder("utf-8").decode(fileBytes);168 const contents = new TextDecoder("utf-8").decode(fileBytes);
175 return {169 return {