Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide meaningful error message when clipboard format is unavailble #56

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions clipboard_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package clipboard

import (
"errors"
"runtime"
"syscall"
"time"
Expand All @@ -33,6 +34,8 @@ var (
globalLock = kernel32.NewProc("GlobalLock")
globalUnlock = kernel32.NewProc("GlobalUnlock")
lstrcpy = kernel32.NewProc("lstrcpyW")

ErrFormatUnavailable = errors.New("clipboard format is unavailable")
)

// waitOpenClipboard opens the clipboard, waiting for up to a second to do so.
Expand All @@ -56,8 +59,8 @@ func readAll() (string, error) {
// Otherwise if the goroutine switch thread during execution (which is a common practice), the OpenClipboard and CloseClipboard will happen on two different threads, and it will result in a clipboard deadlock.
runtime.LockOSThread()
defer runtime.UnlockOSThread()
if formatAvailable, _, err := isClipboardFormatAvailable.Call(cfUnicodetext); formatAvailable == 0 {
return "", err
if formatAvailable, _, _ := isClipboardFormatAvailable.Call(cfUnicodetext); formatAvailable == 0 {
return "", ErrFormatUnavailable
}
err := waitOpenClipboard()
if err != nil {
Expand Down