From ce089f7e2d45c6d468aea036e25e2cf10c3aa4e9 Mon Sep 17 00:00:00 2001 From: Srigovind Nayak <5201843+konidev20@users.noreply.github.com> Date: Tue, 3 Jun 2025 14:34:12 +0530 Subject: [PATCH] errors: standardize error wrapping for Fatal errors * replace all occurences of `errors.Fatal(err.Error())` with `errors.Fatalf("%s", err)` so that the error wrapping is correct across the codebase * updated the review comments --- cmd/restic/cmd_copy.go | 2 +- cmd/restic/cmd_diff.go | 2 +- cmd/restic/cmd_init.go | 2 +- cmd/restic/global.go | 4 ++-- internal/repository/prune.go | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cmd/restic/cmd_copy.go b/cmd/restic/cmd_copy.go index 2ad5a464c..02bc027c8 100644 --- a/cmd/restic/cmd_copy.go +++ b/cmd/restic/cmd_copy.go @@ -250,7 +250,7 @@ func copyTree(ctx context.Context, srcRepo restic.Repository, dstRepo restic.Rep ) bar.Done() if err != nil { - return errors.Fatal(err.Error()) + return errors.Fatalf("%s", err) } return nil } diff --git a/cmd/restic/cmd_diff.go b/cmd/restic/cmd_diff.go index e065ba4b6..5d321e7f3 100644 --- a/cmd/restic/cmd_diff.go +++ b/cmd/restic/cmd_diff.go @@ -72,7 +72,7 @@ func (opts *DiffOptions) AddFlags(f *pflag.FlagSet) { func loadSnapshot(ctx context.Context, be restic.Lister, repo restic.LoaderUnpacked, desc string) (*restic.Snapshot, string, error) { sn, subfolder, err := restic.FindSnapshot(ctx, be, repo, desc) if err != nil { - return nil, "", errors.Fatal(err.Error()) + return nil, "", errors.Fatalf("%s", err) } return sn, subfolder, err } diff --git a/cmd/restic/cmd_init.go b/cmd/restic/cmd_init.go index d66163af1..c31cb1cbd 100644 --- a/cmd/restic/cmd_init.go +++ b/cmd/restic/cmd_init.go @@ -101,7 +101,7 @@ func runInit(ctx context.Context, opts InitOptions, gopts GlobalOptions, args [] PackSize: gopts.PackSize * 1024 * 1024, }) if err != nil { - return errors.Fatal(err.Error()) + return errors.Fatalf("%s", err) } err = s.Init(ctx, version, gopts.password, chunkerPolynomial) diff --git a/cmd/restic/global.go b/cmd/restic/global.go index 6e58a0d73..c48960559 100644 --- a/cmd/restic/global.go +++ b/cmd/restic/global.go @@ -486,7 +486,7 @@ func OpenRepository(ctx context.Context, opts GlobalOptions) (*repository.Reposi NoExtraVerify: opts.NoExtraVerify, }) if err != nil { - return nil, errors.Fatal(err.Error()) + return nil, errors.Fatalf("%s", err) } passwordTriesLeft := 1 @@ -613,7 +613,7 @@ func innerOpen(ctx context.Context, s string, gopts GlobalOptions, opts options. rt, err := backend.Transport(globalOptions.TransportOptions) if err != nil { - return nil, errors.Fatal(err.Error()) + return nil, errors.Fatalf("%s", err) } // wrap the transport so that the throughput via HTTP is limited diff --git a/internal/repository/prune.go b/internal/repository/prune.go index 9726a6032..30152e208 100644 --- a/internal/repository/prune.go +++ b/internal/repository/prune.go @@ -567,7 +567,7 @@ func (plan *PrunePlan) Execute(ctx context.Context, printer progress.Printer) er _, err := Repack(ctx, repo, repo, plan.repackPacks, plan.keepBlobs, bar, printer.P) bar.Done() if err != nil { - return errors.Fatal(err.Error()) + return errors.Fatalf("%s", err) } // Also remove repacked packs