Skip to content

Commit 6ef8af5

Browse files
committed
fix: getting unsuported formats from clipboard returning unhelpful error message
ref #983
1 parent a2ea5ac commit 6ef8af5

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/ziggy/commands/clipboard.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package commands
22

33
import (
4+
"errors"
45
"flag"
56
"fmt"
7+
"strings"
68
"uosc/bins/src/ziggy/lib"
79

810
"github.com/atotto/clipboard"
@@ -13,8 +15,18 @@ type ClipboardResult struct {
1315
}
1416

1517
func GetClipboard(_ []string) {
18+
// We need to do this instead of just `Payload: lib.Must(clipboard.ReadAll())` because
19+
// the atotto/clipboard returns unhelpful messages like "the operation completed successfully".
20+
payload, err := clipboard.ReadAll()
21+
if err != nil {
22+
if strings.Contains(strings.ToLower(err.Error()), "successfully") {
23+
lib.Check(errors.New("clipboard format not supported"))
24+
}
25+
lib.Check(err)
26+
}
27+
1628
fmt.Print(string(lib.Must(lib.JSONMarshal(ClipboardResult{
17-
Payload: lib.Must(clipboard.ReadAll()),
29+
Payload: payload,
1830
}))))
1931
}
2032

0 commit comments

Comments
 (0)