Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Chiusa Adatta ai principianti
#54,413 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
75/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
cli, tooling

Direzione di ricerca

Leggi packages/tui/src/clipboard.ts e packages/tui/src/util/selection.ts, poi esamina i test degli appunti in packages/tui/test/clipboard.test.ts. Segui il percorso degli errori di scrittura fino al gestore della selezione e verifica come vengono gestite le funzioni di supporto degli appunti non disponibili. Il lavoro è completo quando le scritture non riuscite non attivano più una notifica di successo e i test coprono il comportamento in caso di errore.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
Lingua principale
TypeScript
Stelle
213k
Fork
28.4k
Merge medio
7h 22m
PR unite (30g)
276

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di anomalyco/opencode

Tutte le issue di anomalyco/opencode

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.