Skip to content

Conversation

@ochen1
Copy link

@ochen1 ochen1 commented Jan 2, 2026

Problem

TL;DR - attach/mention (e.g., @somefile.txt) any file and ask OpenCode to delete it, wait for completion, up arrow, enter.

When a user attached a file (e.g., @somefile.txt) and that file was deleted before submitting the message, Bun.file(filepath).stat() threw an unhandled ENOENT error that printed raw to the TUI, breaking the display: e.g.

ENOENT: no such file or directory, statx '/workspace/ANALYSIS_INDEX.md'
    path: "/workspace/ANALYSIS_INDEX.md",
 syscall: "statx",
   errno: -2,
    code: "ENOENT"
Screenshot 2026-01-02 105744

Solution

Wrap the stat() call with .catch(() => null) and handle the missing file case:

  1. Publish Session.Event.Error - triggers a toast notification in TUI
  2. Add a synthetic text part with the error message - visible to the model
  3. Preserve the original file part - user's intent is recorded
    This follows the existing pattern used by ReadTool error handling in the same file.

Testing

Screenshot 2026-01-02 111516 Screenshot 2026-01-02 113007

When a user attaches a file that no longer exists, the stat() call
would throw an unhandled ENOENT error that printed raw to the TUI,
breaking the display.

Now the error is caught and handled gracefully:
- A Session.Event.Error is published (shows toast in TUI)
- An error message is added to the conversation as a synthetic part
- The message is still created with the user's intent preserved

This follows the existing pattern used by ReadTool error handling.
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.

1 participant