Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Copy failures are silently swallowed — TUI shows "Copied to clipboard" even when nothing is copied

Đã đóng Phù hợp với người mới
#54,413 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
75/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript
Lĩnh vực
cli, tooling

Hướng nghiên cứu

Đọc packages/tui/src/clipboard.ts và packages/tui/src/util/selection.ts, sau đó xem các bài kiểm thử clipboard trong packages/tui/test/clipboard.test.ts. Theo dõi cách lỗi ghi được truyền đến trình xử lý lựa chọn và cách xử lý các hàm trợ giúp clipboard không khả dụng. Hoàn thành khi thao tác ghi thất bại không còn kích hoạt thông báo thành công và có bài kiểm thử bao quát hành vi khi xảy ra lỗi.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

pending close triaging

Title: Copy failures are silently swallowed — TUI shows "Copied to clipboard" even when nothing is copied

Summary

Every clipboard write path in the TUI swallows its error, so write() always resolves. The selection handler shows the success toast on .then(), meaning the "Copied to clipboard" message appears on every copy attempt, including ones where the text never reached the clipboard.

Steps to reproduce

  1. On Linux, have no clipboard helper binary installed (no wl-copy, xclip, or xsel).
  2. Launch the TUI, select any text, press ctrl+c (or use the copy action).
  3. Observe: the "Copied to clipboard" toast appears.
  4. Paste elsewhere: the clipboard is unchanged.

Confirmed on a Wayland session with opencode 1.18.34.

Root cause

In packages/tui/src/clipboard.ts, every branch discards its failure:

// line 106 — osascript
await command("osascript", ["-e", `set the clipboard to "${escaped}"`]).catch(() => undefined)

// line 111 — native helper (wl-copy / xclip / xsel / powershell)
await command(native[0], native.slice(1), text).catch(() => undefined)

// line 116 — clipboardy fallback
await clipboardy.write(text).catch(() => undefined)

write() therefore never rejects, and the consumer in packages/tui/src/util/selection.ts treats a resolved promise as proof of success:

clipboard
  ?.write?.(clipboardText)
  .then(() => toast.show({ message: "Copied to clipboard", variant: "info" }))
  .catch(toast.error)

The .catch(toast.error) on the last line is unreachable for copy failures — that is the bug.

Note that on Linux clipboardy itself shells out to xsel/xclip, so the fallback does not rescue this case: it fails the same way, and is swallowed the same way.

Why it is confusing

The toast is a false signal. It reports intent rather than outcome, so there is no way to tell from the UI whether a copy succeeded. In my case the underlying cause was simply a missing wl-clipboard package, which took a while to track down precisely because the UI insisted the copy had worked.

Suggested fix

Two parts, both small:

  1. Propagate errors. Let getCopyMethod()'s helpers reject instead of .catch(() => undefined), so write() rejects and the existing .catch(toast.error) in selection.ts:40 fires and shows a real error.
  2. Warn once when no clipboard mechanism exists. copyCommand() already returns undefined in this situation (packages/tui/test/clipboard.test.ts:17 covers exactly that case). Surfacing that at startup — or at least falling back to the OSC 52 sequence with an explicit note — would have made this self-diagnosing.

Additional consideration

writeOsc52() at the top of write() writes the escape sequence to stdout without any verification that the terminal honoured it. Many terminals do not implement OSC 52 set-clipboard, or gate it behind an allowlist. If OSC 52 is the only mechanism available, the success toast is still inaccurate.

Environment

  • opencode 1.18.34
  • Linux, Wayland session
  • No wl-copy, xclip, or xsel installed
Ngôn ngữ chính
TypeScript
Star
213k
Fork
28.4k
Merge trung bình
8 giờ 58 phút
Pull request đã merge (30 ngày)
251

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của anomalyco/opencode

Tất cả issue của anomalyco/opencode

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.