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

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

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

State: open
Merged: No


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.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/10734 **State:** open **Merged:** No --- ### 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.
yindo added the pull-request label 2026-02-16 18:18:23 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13544