From e6d56953da10bba5bb71b813d524d73c1346b18e Mon Sep 17 00:00:00 2001 From: George Brighton Date: Sat, 30 Apr 2022 23:17:41 +0100 Subject: [PATCH] Use error wrapping Closes #26. --- main.go | 2 +- monitor/monitor.go | 4 ++-- uploader/uploader.go | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 595e927..f38bc59 100644 --- a/main.go +++ b/main.go @@ -74,7 +74,7 @@ func backupLoop(uploader *uploader.Uploader, monitor *monitor.Monitor, timeout t } cancel() case err := <-monitor.Errors: - return fmt.Errorf("monitor error: %v", err) + return fmt.Errorf("monitor error: %w", err) case <-done: return nil } diff --git a/monitor/monitor.go b/monitor/monitor.go index 74e59c2..c8c14f4 100644 --- a/monitor/monitor.go +++ b/monitor/monitor.go @@ -85,11 +85,11 @@ func (m *Monitor) Close() error { func New(dir string) (*Monitor, error) { watcher, err := fsnotify.NewWatcher() if err != nil { - return nil, fmt.Errorf("failed to create watcher: %v", err) + return nil, fmt.Errorf("failed to create watcher: %w", err) } if err = watcher.Add(dir); err != nil { watcher.Close() - return nil, fmt.Errorf("failed to watch %v: %v", dir, err) + return nil, fmt.Errorf("failed to watch %v: %w", dir, err) } return &Monitor{ watcher: watcher, diff --git a/uploader/uploader.go b/uploader/uploader.go index 3a86c02..06dd8b2 100644 --- a/uploader/uploader.go +++ b/uploader/uploader.go @@ -88,7 +88,7 @@ func (u *Uploader) Upload(ctx context.Context, path string) (*s3manager.UploadOu f, err := os.Open(path) if err != nil { uploadFailures.Inc() - return nil, fmt.Errorf("failed to open %v for uploading: %v", path, err) + return nil, fmt.Errorf("failed to open %v for uploading: %w", path, err) } defer f.Close() @@ -103,7 +103,7 @@ func (u *Uploader) Upload(ctx context.Context, path string) (*s3manager.UploadOu }) if err != nil { uploadFailures.Inc() - return nil, fmt.Errorf("failed to upload %v: %v", base, err) + return nil, fmt.Errorf("failed to upload %v: %w", base, err) } elapsed := time.Since(start) uploadDuration.Set(elapsed.Seconds())