Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit 55787f2

Browse files
authored
fix: tui: Handle Clipboard.copy errors properly (anomalyco#3685)
1 parent 7df61a7 commit 55787f2

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

packages/opencode/src/cli/cmd/tui/app.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,9 @@ function App() {
296296
/* @ts-expect-error */
297297
renderer.writeOut(finalOsc52)
298298
await Clipboard.copy(text)
299+
.then(() => toast.show({ message: "Copied to clipboard", variant: "info" }))
300+
.catch(toast.error)
299301
renderer.clearSelection()
300-
toast.show({ message: "Copied to clipboard", variant: "info" })
301302
}
302303
}}
303304
>

packages/opencode/src/cli/cmd/tui/ui/toast.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function init() {
4949

5050
let timeoutHandle: NodeJS.Timeout | null = null
5151

52-
return {
52+
const toast = {
5353
show(options: ToastOptions) {
5454
const parsedOptions = TuiEvent.ToastShow.properties.parse(options)
5555
const { duration, ...currentToast } = parsedOptions
@@ -59,10 +59,22 @@ function init() {
5959
setStore("currentToast", null)
6060
}, duration).unref()
6161
},
62+
error: (err: any) => {
63+
if (err instanceof Error)
64+
return toast.show({
65+
variant: "error",
66+
message: err.message,
67+
})
68+
toast.show({
69+
variant: "error",
70+
message: "An unknown error has occurred",
71+
})
72+
},
6273
get currentToast(): ToastOptions | null {
6374
return store.currentToast
6475
},
6576
}
77+
return toast
6678
}
6779

6880
export type ToastContext = ReturnType<typeof init>

packages/opencode/src/cli/cmd/tui/util/clipboard.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export namespace Clipboard {
7676
const proc = Bun.spawn(["wl-copy"], { stdin: "pipe", stdout: "ignore", stderr: "ignore" })
7777
proc.stdin.write(text)
7878
proc.stdin.end()
79-
await proc.exited.catch(() => {})
79+
await proc.exited
8080
}
8181
}
8282
if (Bun.which("xclip")) {
@@ -117,7 +117,7 @@ export namespace Clipboard {
117117

118118
console.log("clipboard: no native support")
119119
return async (text: string) => {
120-
await clipboardy.write(text).catch(() => {})
120+
await clipboardy.write(text)
121121
}
122122
})
123123

0 commit comments

Comments
 (0)