better error messages
This commit is contained in:
parent
0f95eedd08
commit
b231836f35
2 changed files with 9 additions and 4 deletions
11
demon.go
11
demon.go
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os/exec"
|
||||
"time"
|
||||
|
@ -46,8 +47,12 @@ func listen(history []string, histfile string, persist bool, max int) error {
|
|||
for {
|
||||
|
||||
t, err := exec.Command("wl-paste", []string{"-n", "-t", "text"}...).Output()
|
||||
if err != nil {
|
||||
return fmt.Errorf("error running wl-paste (demon.52): %s", err)
|
||||
}
|
||||
|
||||
text := string(t)
|
||||
if err != nil || text == "" {
|
||||
if text == "" {
|
||||
// there's nothing to select, so we sleep.
|
||||
time.Sleep(1 * time.Second)
|
||||
continue
|
||||
|
@ -80,14 +85,14 @@ func listen(history []string, histfile string, persist bool, max int) error {
|
|||
// dump history to file so that other apps can query it
|
||||
err = write(history, histfile)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("error writing history (demon.83): %s", err)
|
||||
}
|
||||
|
||||
if persist {
|
||||
// make the copy buffer available to all applications,
|
||||
// even when the source has disappeared
|
||||
if err := exec.Command("wl-copy", text).Run(); err != nil {
|
||||
return err
|
||||
return fmt.Errorf("error running wl-copy (demon.91): %s", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
2
main.go
2
main.go
|
@ -35,7 +35,7 @@ func main() {
|
|||
b, err := ioutil.ReadFile(histfile)
|
||||
if err == nil {
|
||||
if err := json.Unmarshal(b, &history); err != nil {
|
||||
log.Fatal(err)
|
||||
log.Fatalf("Failure unmarshaling history (main.38): %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue