cleanup: wrap errors properly (#772)

* cleanup: wrap errors properly

* fix build error

* asdfg linux

* fix test
This commit is contained in:
Maia McCormick 2018-11-30 12:05:15 -05:00 committed by Nicolas De loof
parent 38b3f3b678
commit 139edc403f
1 changed files with 7 additions and 7 deletions

View File

@ -1,7 +1,6 @@
package watch package watch
import ( import (
"fmt"
"io/ioutil" "io/ioutil"
"log" "log"
"os" "os"
@ -9,6 +8,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/pkg/errors"
"github.com/windmilleng/fsnotify" "github.com/windmilleng/fsnotify"
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
@ -29,27 +29,27 @@ type linuxNotify struct {
func (d *linuxNotify) Add(name string) error { func (d *linuxNotify) Add(name string) error {
fi, err := os.Stat(name) fi, err := os.Stat(name)
if err != nil && !os.IsNotExist(err) { 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) { if os.IsNotExist(err) {
parent := filepath.Join(name, "..") parent := filepath.Join(name, "..")
err = d.watcher.Add(parent) err = d.watcher.Add(parent)
if err != nil { if err != nil {
return fmt.Errorf("notify.Add(%q): %v", name, err) return errors.Wrapf(err, "notify.Add(%q)", name)
} }
d.watchList[parent] = true d.watchList[parent] = true
} else if fi.IsDir() { } else if fi.IsDir() {
err = d.watchRecursively(name) err = d.watchRecursively(name)
if err != nil { if err != nil {
return fmt.Errorf("notify.Add(%q): %v", name, err) return errors.Wrapf(err, "notify.Add(%q)", name)
} }
d.watchList[name] = true d.watchList[name] = true
} else { } else {
err = d.watcher.Add(name) err = d.watcher.Add(name)
if err != nil { if err != nil {
return fmt.Errorf("notify.Add(%q): %v", name, err) return errors.Wrapf(err, "notify.Add(%q)", name)
} }
d.watchList[name] = true d.watchList[name] = true
} }
@ -68,7 +68,7 @@ func (d *linuxNotify) watchRecursively(dir string) error {
if os.IsNotExist(err) { if os.IsNotExist(err) {
return nil return nil
} }
return fmt.Errorf("watcher.Add(%q): %v", path, err) return errors.Wrapf(err, "watcher.Add(%q)", path)
} }
return nil return nil
}) })