From 1fe0de253c84ab24ddaca5b3317e8ffa276dc4ce Mon Sep 17 00:00:00 2001 From: uf <15956652+udyr-f@users.noreply.github.com> Date: Tue, 3 Feb 2026 12:55:06 +0800 Subject: [PATCH] fix(clipboard): report actual copy result instead of always showing success Previously clipboard copy operations silently swallowed errors, showing "Copied to clipboard" even when the copy failed. This was confusing on Linux systems without xclip/xsel/wl-copy installed. Changes: - Check exit codes for all clipboard commands - Throw descriptive errors on failure - Show clear error message when no clipboard tool is available on Linux --- .../opencode/src/cli/cmd/tui/util/clipboard.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/opencode/src/cli/cmd/tui/util/clipboard.ts b/packages/opencode/src/cli/cmd/tui/util/clipboard.ts index 5c27a26cd039..df5c9ca3f429 100644 --- a/packages/opencode/src/cli/cmd/tui/util/clipboard.ts +++ b/packages/opencode/src/cli/cmd/tui/util/clipboard.ts @@ -72,7 +72,8 @@ export namespace Clipboard { console.log("clipboard: using osascript") return async (text: string) => { const escaped = text.replace(/\\/g, "\\\\").replace(/"/g, '\\"') - await $`osascript -e 'set the clipboard to "${escaped}"'`.nothrow().quiet() + const result = await $`osascript -e 'set the clipboard to "${escaped}"'`.nothrow().quiet() + if (result.exitCode !== 0) throw new Error("osascript failed") } } @@ -83,7 +84,8 @@ export namespace Clipboard { const proc = Bun.spawn(["wl-copy"], { stdin: "pipe", stdout: "ignore", stderr: "ignore" }) proc.stdin.write(text) proc.stdin.end() - await proc.exited.catch(() => {}) + const code = await proc.exited + if (code !== 0) throw new Error("wl-copy failed") } } if (Bun.which("xclip")) { @@ -96,7 +98,8 @@ export namespace Clipboard { }) proc.stdin.write(text) proc.stdin.end() - await proc.exited.catch(() => {}) + const code = await proc.exited + if (code !== 0) throw new Error("xclip failed") } } if (Bun.which("xsel")) { @@ -109,9 +112,11 @@ export namespace Clipboard { }) proc.stdin.write(text) proc.stdin.end() - await proc.exited.catch(() => {}) + const code = await proc.exited + if (code !== 0) throw new Error("xsel failed") } } + throw new Error("No clipboard tool found. Install xclip, xsel, or wl-clipboard.") } if (os === "win32") { @@ -135,13 +140,14 @@ export namespace Clipboard { proc.stdin.write(text) proc.stdin.end() - await proc.exited.catch(() => {}) + const code = await proc.exited + if (code !== 0) throw new Error("powershell clipboard failed") } } console.log("clipboard: no native support") return async (text: string) => { - await clipboardy.write(text).catch(() => {}) + await clipboardy.write(text) } })