Skip to content

fix(core): catch EISDIR (BadResource) in readFileStringSafe to prevent crash on launch#32228

Open
imharjot wants to merge 1 commit into
anomalyco:devfrom
imharjot:fix/readfilestringsafe-eisdir
Open

fix(core): catch EISDIR (BadResource) in readFileStringSafe to prevent crash on launch#32228
imharjot wants to merge 1 commit into
anomalyco:devfrom
imharjot:fix/readfilestringsafe-eisdir

Conversation

@imharjot

Copy link
Copy Markdown

Issue for this PR

Closes #32205

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

readFileStringSafe in packages/core/src/fs-util.ts only caught the NotFound PlatformError. When a probed config path happens to be a directory, Node throws EISDIR, which Effect maps to the BadResource reason. That error slipped past the single catchReason and, because config loading wraps these reads in Effect.orDie (packages/opencode/src/config/config.ts and packages/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 catchReason for BadResource so a directory match returns undefined, 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 readFileStringSafe block in packages/core/test/filesystem/filesystem.test.ts that creates a temp directory, points readFileStringSafe at it, and expects undefined. Against the old code that test fails with EISDIR ... BadResource; with the fix it passes. Ran bun test test/filesystem/filesystem.test.ts from packages/core (28 pass / 0 fail), plus tsgo --noEmit typecheck and oxlint, all clean.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

readFileStringSafe does not catch EISDIR - TUI crashes on every launch with Unexpected server error (exit 133 / SIGTRAP)

1 participant