From 139edc403f6940fd51f8769c4ef3b5fd49c300ae Mon Sep 17 00:00:00 2001 From: Maia McCormick Date: Fri, 30 Nov 2018 12:05:15 -0500 Subject: [PATCH] cleanup: wrap errors properly (#772) * cleanup: wrap errors properly * fix build error * asdfg linux * fix test --- pkg/watch/watcher_linux.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/watch/watcher_linux.go b/pkg/watch/watcher_linux.go index d1adca60e..307e69a73 100644 --- a/pkg/watch/watcher_linux.go +++ b/pkg/watch/watcher_linux.go @@ -1,7 +1,6 @@ package watch import ( - "fmt" "io/ioutil" "log" "os" @@ -9,6 +8,7 @@ import ( "strconv" "strings" + "github.com/pkg/errors" "github.com/windmilleng/fsnotify" "google.golang.org/grpc" "google.golang.org/grpc/codes" @@ -29,27 +29,27 @@ type linuxNotify struct { func (d *linuxNotify) Add(name string) error { fi, err := os.Stat(name) if err != nil && !os.IsNotExist(err) { - return fmt.Errorf("notify.Add(%q): %v", name, err) + return errors.Wrapf(err, "notify.Add(%q)", name) } - // if it's a file that doesn't exist watch it's parent + // if it's a file that doesn't exist, watch its parent if os.IsNotExist(err) { parent := filepath.Join(name, "..") err = d.watcher.Add(parent) if err != nil { - return fmt.Errorf("notify.Add(%q): %v", name, err) + return errors.Wrapf(err, "notify.Add(%q)", name) } d.watchList[parent] = true } else if fi.IsDir() { err = d.watchRecursively(name) if err != nil { - return fmt.Errorf("notify.Add(%q): %v", name, err) + return errors.Wrapf(err, "notify.Add(%q)", name) } d.watchList[name] = true } else { err = d.watcher.Add(name) if err != nil { - return fmt.Errorf("notify.Add(%q): %v", name, err) + return errors.Wrapf(err, "notify.Add(%q)", name) } d.watchList[name] = true } @@ -68,7 +68,7 @@ func (d *linuxNotify) watchRecursively(dir string) error { if os.IsNotExist(err) { return nil } - return fmt.Errorf("watcher.Add(%q): %v", path, err) + return errors.Wrapf(err, "watcher.Add(%q)", path) } return nil })