fix(core): catch EISDIR (BadResource) in readFileStringSafe to prevent crash on launch#32228
Open
imharjot wants to merge 1 commit into
Open
fix(core): catch EISDIR (BadResource) in readFileStringSafe to prevent crash on launch#32228imharjot wants to merge 1 commit into
imharjot wants to merge 1 commit into
Conversation
…t crash on launch readFileStringSafe only caught the NotFound PlatformError, so when a probed config path happened to be a directory, Node threw EISDIR. Effect maps that to the BadResource reason, which escaped the catch and turned into a defect via the Effect.orDie chains in config loading, crashing the TUI on every launch. Catch BadResource as well and return undefined, matching the existing NotFound behaviour so a directory match is treated like a missing file. All other PlatformErrors stay fatal. Closes anomalyco#32205 Signed-off-by: Harjot Singh <harjotsrance@gmail.com>
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.
Issue for this PR
Closes #32205
Type of change
What does this PR do?
readFileStringSafeinpackages/core/src/fs-util.tsonly caught theNotFoundPlatformError. When a probed config path happens to be a directory, Node throwsEISDIR, which Effect maps to theBadResourcereason. That error slipped past the singlecatchReasonand, because config loading wraps these reads inEffect.orDie(packages/opencode/src/config/config.tsandpackages/core/src/config.ts), it became a fatal defect — so the TUI crashed on launch whenever a directory sat where a config file was expected.The fix chains a second
catchReasonforBadResourceso a directory match returnsundefined, the same way a missing file already does. Every other PlatformError stays fatal, so genuine read failures still surface.How did you verify your code works?
Added a case to the existing
readFileStringSafeblock inpackages/core/test/filesystem/filesystem.test.tsthat creates a temp directory, pointsreadFileStringSafeat it, and expectsundefined. Against the old code that test fails withEISDIR ... BadResource; with the fix it passes. Ranbun test test/filesystem/filesystem.test.tsfrompackages/core(28 pass / 0 fail), plustsgo --noEmittypecheck andoxlint, all clean.Screenshots / recordings
Not a UI change.
Checklist