fix(opencode): handle http/https URLs in file parts and prevent ENOENT crash#10734
fix(opencode): handle http/https URLs in file parts and prevent ENOENT crash#10734rynfar wants to merge 1 commit into
Conversation
|
The following comment was made by an LLM, it may be inaccurate: Found a potentially related PR: PR #6666: fix(opencode): handle ENOENT when attached file is deleted Why it's related: This PR also addresses ENOENT error handling for file operations in opencode, specifically when an attached file is deleted. While the current PR (10734) handles ENOENT for missing files and adds protocol handling for http/https URLs, PR #6666 tackles a similar error condition (ENOENT) in the same codebase. These may overlap in scope or address related issues in file handling. |
|
Checked #6666 — it fixes the same Updating to incorporate #6666's more thorough error handling (Bus.publish for toast + preserve original part) so either PR can be merged independently. |
1ba019e to
d12a932
Compare
00637c0 to
71e0ba2
Compare
f1ae801 to
08fa7f7
Compare
|
Closing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR. |
What does this PR do?
Fixes #10730
When a file part has an
http:orhttps:URL (e.g., a GitHub image URL), the switch statement increateUserMessagehad no matching case. If such a URL was ever wrapped in afile://scheme, the unhandledBun.file(filepath).stat()call would throw ENOENT and crash the TUI.Two changes:
case "http:"/case "https:"to the protocol switch — returns the part as-is instead of falling through silently.catch(() => undefined)toBun.file(filepath).stat()in thefile:case — if the file doesn't exist, returns a "File not found" text part instead of crashingHow did you verify your code works?
Traced the code path in
packages/opencode/src/session/prompt.tscreateUserMessage. Thestat()call on line 953 (now 963) had no error handling — any ENOENT would propagate throughPromise.alland crash. Verified the fix handles both cases: unknown protocols return gracefully, and missing files produce a user-visible message instead of a raw error dump.