Skip to content

Commit

Permalink
Use error wrapping
Browse files Browse the repository at this point in the history
Closes #26.
  • Loading branch information
gebn committed Apr 30, 2022
1 parent ff264fc commit e6d5695
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions uploader/uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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())
Expand Down

0 comments on commit e6d5695

Please sign in to comment.