aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2018-07-27 12:55:32 +0200
committerMartin Polden <mpolden@mpolden.no>2018-07-27 12:55:32 +0200
commitac5582a1e73b4d320d551dafbfc78d1afdfeeaa1 (patch)
treedae6b7fc686ce01b52c40956930b289cfadf8b7b
parentb877a58355dd8c1ddb896b2ab26118e84f427be9 (diff)
Clean up error messages
-rw-r--r--rar/rar.go21
-rw-r--r--watcher/watcher.go4
2 files changed, 13 insertions, 12 deletions
diff --git a/rar/rar.go b/rar/rar.go
index 266c1c0..1e8400d 100644
--- a/rar/rar.go
+++ b/rar/rar.go
@@ -178,19 +178,19 @@ func (u *unpacker) verify() error {
return nil
}
-func (u *unpacker) run(removeRARs bool) error {
+func (u *unpacker) Run(removeRARs bool) error {
if exists, total := u.fileCount(); exists != total {
- return errors.Errorf("%s is incomplete: %d/%d files", u.dir, exists, total)
+ return errors.Errorf("incomplete: %s: %d/%d files", u.dir, exists, total)
}
if err := u.verify(); err != nil {
- return errors.Wrapf(err, "verification of %s failed", u.dir)
+ return errors.Wrapf(err, "verification failed: %s", u.dir)
}
if err := u.unpack(u.name); err != nil {
- return errors.Wrapf(err, "unpacking %s failed", u.dir)
+ return errors.Wrapf(err, "unpacking failed: %s", u.dir)
}
if removeRARs {
if err := u.remove(); err != nil {
- return errors.Wrapf(err, "cleaning up %s failed", u.dir)
+ return errors.Wrapf(err, "removal failed: %s", u.dir)
}
}
return nil
@@ -211,21 +211,22 @@ func postProcess(u *unpacker, command string) error {
var stderr bytes.Buffer
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
- return errors.Errorf("%s: %s", err, stderr.String())
+ return errors.Wrapf(err, "stderr: %q", stderr.String())
}
return nil
}
func Unpack(name, postCommand string, remove bool) error {
- u, err := newUnpacker(filepath.Dir(name))
+ path := filepath.Dir(name)
+ u, err := newUnpacker(path)
if err != nil {
- return errors.Wrap(err, "failed to initialize unpacker")
+ return errors.Wrapf(err, "failed to create unpacker: %s", path)
}
- if err := u.run(remove); err != nil {
+ if err := u.Run(remove); err != nil {
return err
}
if err := postProcess(u, postCommand); err != nil {
- return errors.Wrap(err, "post-process command failed")
+ return errors.Wrapf(err, "post-process command failed: %s", path)
}
return nil
}
diff --git a/watcher/watcher.go b/watcher/watcher.go
index d5d379b..0f7fee0 100644
--- a/watcher/watcher.go
+++ b/watcher/watcher.go
@@ -82,7 +82,7 @@ func (w *watcher) rescan() {
return nil
}
if err := w.handle(path); err != nil {
- w.log.Printf("ignoring event: %s", err)
+ w.log.Print(err)
}
return nil
})
@@ -123,7 +123,7 @@ func (w *watcher) readEvent() {
case ev := <-w.events:
w.mu.Lock()
if err := w.handle(ev.Path()); err != nil {
- w.log.Printf("ignoring event: %s", err)
+ w.log.Print(err)
}
w.mu.Unlock()
}