Skip to content

fix(opencode): handle http/https URLs in file parts and prevent ENOENT crash#10734

Closed
rynfar wants to merge 1 commit into
anomalyco:devfrom
rynfar:fix/url-as-filepath-enoent
Closed

fix(opencode): handle http/https URLs in file parts and prevent ENOENT crash#10734
rynfar wants to merge 1 commit into
anomalyco:devfrom
rynfar:fix/url-as-filepath-enoent

Conversation

@rynfar

@rynfar rynfar commented Jan 26, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #10730

When a file part has an http: or https: URL (e.g., a GitHub image URL), the switch statement in createUserMessage had no matching case. If such a URL was ever wrapped in a file:// scheme, the unhandled Bun.file(filepath).stat() call would throw ENOENT and crash the TUI.

Two changes:

  1. Added case "http:" / case "https:" to the protocol switch — returns the part as-is instead of falling through silently
  2. Added .catch(() => undefined) to Bun.file(filepath).stat() in the file: case — if the file doesn't exist, returns a "File not found" text part instead of crashing

How did you verify your code works?

Traced the code path in packages/opencode/src/session/prompt.ts createUserMessage. The stat() call on line 953 (now 963) had no error handling — any ENOENT would propagate through Promise.all and 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.

@github-actions

Copy link
Copy Markdown
Contributor

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.

@rynfar

rynfar commented Jan 26, 2026

Copy link
Copy Markdown
Contributor Author

Checked #6666 — it fixes the same stat() call with .catch(() => null) but for a different trigger (deleted file attachment). Our PR overlaps on that fix but also adds case "http:" / case "https:" protocol handling which #6666 doesn't cover.

Updating to incorporate #6666's more thorough error handling (Bus.publish for toast + preserve original part) so either PR can be merged independently.

@github-actions

Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions Bot closed this Mar 28, 2026
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.

[BUG]: ENOENT when image URL is treated as local file path — breaks TUI rendering

1 participant