[PR #12592] feat: Pass through data URLs directly and gracefully handle unknown U… #14288

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

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

State: open
Merged: No


Summary

Fixes #12547

Error: TypeError: The URL must be of scheme file (ERR_INVALID_URL_SCHEME)

Root Cause

In prompt.ts, the switch statement at line 946 handles URL protocols:

  • case "data:" only processes text/plain mime types, then breaks
  • For clipboard images (image/png), the condition fails and falls through to case "file:"
  • fileURLToPath() is called on a data: URL → crash

Changes

packages/opencode/src/session/prompt.ts

  • Added proper handling for non-text data: URLs (images, PDFs) - returns them as-is for the model
  • Added default case to prevent silent fall-through for unknown protocols

Why This Happens on Windows

Windows clipboard paste encodes images as data:image/png;base64,... URLs via FileReader.readAsDataURL(). The server-side switch statement wasn't handling this case properly.

Testing

  • Paste image from clipboard on Windows 11 - no crash, image attaches correctly
  • File drop still works
  • File picker still works
  • Paste text still works

Checklist

  • Minimal fix addressing root cause
  • No try-catch band-aids
  • Follows existing code patterns
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/12592 **State:** open **Merged:** No --- ## Summary Fixes #12547 **Error:** `TypeError: The URL must be of scheme file (ERR_INVALID_URL_SCHEME)` ## Root Cause In [prompt.ts](cci:7://file:///Users/venom/opencode/packages/app/src/utils/prompt.ts:0:0-0:0), the switch statement at line 946 handles URL protocols: - `case "data:"` only processes `text/plain` mime types, then `break`s - For clipboard images (`image/png`), the condition fails and falls through to `case "file:"` - `fileURLToPath()` is called on a `data:` URL → **crash** ## Changes ### [packages/opencode/src/session/prompt.ts](cci:7://file:///Users/venom/opencode/packages/opencode/src/session/prompt.ts:0:0-0:0) - Added proper handling for non-text `data:` URLs (images, PDFs) - returns them as-is for the model - Added [default](cci:1://file:///Users/venom/opencode/packages/opencode/src/provider/provider.ts:1222:2-1236:3) case to prevent silent fall-through for unknown protocols ## Why This Happens on Windows Windows clipboard paste encodes images as `data:image/png;base64,...` URLs via `FileReader.readAsDataURL()`. The server-side switch statement wasn't handling this case properly. ## Testing - [ ] Paste image from clipboard on Windows 11 - no crash, image attaches correctly - [ ] File drop still works - [ ] File picker still works - [ ] Paste text still works ## Checklist - [x] Minimal fix addressing root cause - [x] No try-catch band-aids - [x] Follows existing code patterns
yindo added the pull-request label 2026-02-16 18:19:05 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#14288