Refactor workspace reads to Effect FileSystem#4050
Draft
cursor[bot] wants to merge 2 commits into
Draft
Conversation
Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
| const stat = yield* Effect.tryPromise({ | ||
| try: () => handle.stat(), | ||
| catch: (cause) => | ||
| return yield* Effect.scoped( |
Contributor
There was a problem hiding this comment.
🟡 Medium workspace/WorkspaceFileSystem.ts:182
When the file handle close fails, readFile now throws an untyped defect instead of a WorkspaceFileSystemOperationError with operation close. The old code wrapped handle.close() failures in a typed error; Effect.scoped delegates cleanup to FileSystem.open's finalizer, which runs Effect.orDie(nodeClose(fd)), so a close failure terminates the effect as a defect rather than through the service's advertised error channel. Consider using Effect.acquireRelease (or Effect.acquireUseRelease) with an explicit close error mapping so close failures remain typed errors.
🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file @apps/server/src/workspace/WorkspaceFileSystem.ts around line 182:
When the file handle close fails, `readFile` now throws an untyped defect instead of a `WorkspaceFileSystemOperationError` with operation `close`. The old code wrapped `handle.close()` failures in a typed error; `Effect.scoped` delegates cleanup to `FileSystem.open`'s finalizer, which runs `Effect.orDie(nodeClose(fd))`, so a close failure terminates the effect as a defect rather than through the service's advertised error channel. Consider using `Effect.acquireRelease` (or `Effect.acquireUseRelease`) with an explicit `close` error mapping so close failures remain typed errors.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Changed
node:fs/promisesandEffect.tryPromisecalls with the injected EffectFileSystemservice.File.stat,File.readAlloc, andOptionfor empty reads.@effect/vitestassertions, asserted normalizedPlatformErrordata, and added preview-limit coverage.Why
The read path bypassed an Effect service that was already injected and used by the write path. Keeping filesystem work inside Effect makes resource safety, structured failures, and layer-based testing consistent end-to-end.
Checklist
Validation:
pnpm exec vp test run src/workspace/WorkspaceFileSystem.test.ts(10 passed)pnpm exec vp check(0 errors; 9 pre-existing warnings)pnpm exec vp run typecheck(15 tasks passed)Note
Refactor workspace
readFileto use Effect FileSystem service APIsnode:fs/promisescalls (open/stat/read/close) withFileSystem.open,FileSystem.stat, andhandle.readAllocfrom the Effect platform, usingEffect.scopedfor automatic resource cleanup.readFilereturns at most the 1 MiB preview limit, setsbyteLengthto the full file size, and markstruncated: true.WorkspaceFileSystemOperationErrorwith aPlatformError(including areasontag such asNotFound) in thecausefield, rather than raw Node.js errors.📊 Macroscope summarized ea7294b. 1 file reviewed, 0 issues evaluated, 0 issues filtered, 0 comments posted
🗂️ Filtered Issues
No issues evaluated.