From b231836f3541a77cc2b2b7a6b6bda2f9c6614dc4 Mon Sep 17 00:00:00 2001 From: yory8 <> Date: Tue, 16 Apr 2019 14:21:36 +0200 Subject: [PATCH] better error messages --- demon.go | 11 ++++++++--- main.go | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/demon.go b/demon.go index 95e0d7c..88c3c62 100644 --- a/demon.go +++ b/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) } } } diff --git a/main.go b/main.go index 31b8ac1..7136a00 100644 --- a/main.go +++ b/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) } }