[PR #6666] fix(opencode): handle ENOENT when attached file is deleted #12033

Open
opened 2026-02-16 18:16:58 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/6666

State: open
Merged: No


Fixes #8807

Problem

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

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.

Verification

Tested:

  1. Attached @somefile.txt.
  2. Deleted somefile.txt from the OS.
  3. Submitted the message.

Result:
Instead of crashing with a raw TUI error, the client now shows a toast notification and the model receives the error context gracefully.

Screenshot 2026-01-02 111516 Screenshot 2026-01-02 113007
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/6666 **State:** open **Merged:** No --- Fixes #8807 ### Problem **TL;DR** - attach/mention (e.g., `@somefile.txt`) any file and ask OpenCode to delete it, wait for completion, up arrow, enter. ### 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. ### Verification **Tested:** 1. Attached `@somefile.txt`. 2. Deleted `somefile.txt` from the OS. 3. Submitted the message. **Result:** Instead of crashing with a raw TUI error, the client now shows a toast notification and the model receives the error context gracefully. <img width="1795" height="1373" alt="Screenshot 2026-01-02 111516" src="https://github.com/user-attachments/assets/9225775e-5cd5-4467-9dd5-22503656b63e" /> <img width="798" height="504" alt="Screenshot 2026-01-02 113007" src="https://github.com/user-attachments/assets/2920990f-02f0-4d2f-93e6-2ef34a75f974" />
yindo added the pull-request label 2026-02-16 18:16:58 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12033