From 5815f727ee4442873c00463daab56bbfd6f702f6 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sun, 1 May 2022 20:08:02 +0200 Subject: [PATCH] checker: convert error type to use pointer-receivers --- cmd/restic/cmd_check.go | 4 ++-- internal/checker/checker.go | 12 ++++++------ internal/checker/checker_test.go | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cmd/restic/cmd_check.go b/cmd/restic/cmd_check.go index e7edff39e..1993b3304 100644 --- a/cmd/restic/cmd_check.go +++ b/cmd/restic/cmd_check.go @@ -222,7 +222,7 @@ func runCheck(opts CheckOptions, gopts GlobalOptions, args []string) error { dupFound := false for _, hint := range hints { Printf("%v\n", hint) - if _, ok := hint.(checker.ErrDuplicatePacks); ok { + if _, ok := hint.(*checker.ErrDuplicatePacks); ok { dupFound = true } } @@ -273,7 +273,7 @@ func runCheck(opts CheckOptions, gopts GlobalOptions, args []string) error { for err := range errChan { errorsFound = true - if e, ok := err.(checker.TreeError); ok { + if e, ok := err.(*checker.TreeError); ok { Warnf("error for tree %v:\n", e.ID.Str()) for _, treeErr := range e.Errors { Warnf(" %v\n", treeErr) diff --git a/internal/checker/checker.go b/internal/checker/checker.go index 8e49209f5..2ecd1469c 100644 --- a/internal/checker/checker.go +++ b/internal/checker/checker.go @@ -63,7 +63,7 @@ type ErrDuplicatePacks struct { Indexes restic.IDSet } -func (e ErrDuplicatePacks) Error() string { +func (e *ErrDuplicatePacks) Error() string { return fmt.Sprintf("pack %v contained in several indexes: %v", e.PackID.Str(), e.Indexes) } @@ -73,7 +73,7 @@ type ErrOldIndexFormat struct { restic.ID } -func (err ErrOldIndexFormat) Error() string { +func (err *ErrOldIndexFormat) Error() string { return fmt.Sprintf("index %v has old format", err.ID.Str()) } @@ -93,7 +93,7 @@ func (c *Checker) LoadIndex(ctx context.Context) (hints []error, errs []error) { if oldFormat { debug.Log("index %v has old format", id.Str()) - hints = append(hints, ErrOldIndexFormat{id}) + hints = append(hints, &ErrOldIndexFormat{id}) } err = errors.Wrapf(err, "error loading index %v", id.Str()) @@ -137,7 +137,7 @@ func (c *Checker) LoadIndex(ctx context.Context) (hints []error, errs []error) { for packID := range c.packs { debug.Log(" check pack %v: contained in %d indexes", packID, len(packToIndex[packID])) if len(packToIndex[packID]) > 1 { - hints = append(hints, ErrDuplicatePacks{ + hints = append(hints, &ErrDuplicatePacks{ PackID: packID, Indexes: packToIndex[packID], }) @@ -257,7 +257,7 @@ type TreeError struct { Errors []error } -func (e TreeError) Error() string { +func (e *TreeError) Error() string { return fmt.Sprintf("tree %v: %v", e.ID.Str(), e.Errors) } @@ -276,7 +276,7 @@ func (c *Checker) checkTreeWorker(ctx context.Context, trees <-chan restic.TreeI if len(errs) == 0 { continue } - treeError := TreeError{ID: job.ID, Errors: errs} + treeError := &TreeError{ID: job.ID, Errors: errs} select { case <-ctx.Done(): return diff --git a/internal/checker/checker_test.go b/internal/checker/checker_test.go index 2a4384b15..f2ee0c732 100644 --- a/internal/checker/checker_test.go +++ b/internal/checker/checker_test.go @@ -289,7 +289,7 @@ func TestDuplicatePacksInIndex(t *testing.T) { found := false for _, hint := range hints { - if _, ok := hint.(checker.ErrDuplicatePacks); ok { + if _, ok := hint.(*checker.ErrDuplicatePacks); ok { found = true } else { t.Errorf("got unexpected hint: %v", hint)