From 97933d1404652a62398be53585148a3610514f80 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Wed, 24 Sep 2025 22:11:34 +0200 Subject: [PATCH 1/2] remove trailing newlines from errors.Fatalf calls --- cmd/restic/cmd_backup.go | 2 +- cmd/restic/cmd_cat.go | 4 ++-- cmd/restic/cmd_init.go | 4 ++-- cmd/restic/cmd_key_add.go | 2 +- cmd/restic/cmd_key_passwd.go | 2 +- cmd/restic/cmd_restore.go | 4 ++-- cmd/restic/cmd_rewrite.go | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cmd/restic/cmd_backup.go b/cmd/restic/cmd_backup.go index 2c7e209c5..997e702e8 100644 --- a/cmd/restic/cmd_backup.go +++ b/cmd/restic/cmd_backup.go @@ -502,7 +502,7 @@ func runBackup(ctx context.Context, opts BackupOptions, gopts GlobalOptions, ter if opts.TimeStamp != "" { timeStamp, err = time.ParseInLocation(TimeFormat, opts.TimeStamp, time.Local) if err != nil { - return errors.Fatalf("error in time option: %v\n", err) + return errors.Fatalf("error in time option: %v", err) } } diff --git a/cmd/restic/cmd_cat.go b/cmd/restic/cmd_cat.go index 41ea9f5e0..1cbb54ef4 100644 --- a/cmd/restic/cmd_cat.go +++ b/cmd/restic/cmd_cat.go @@ -109,7 +109,7 @@ func runCat(ctx context.Context, gopts GlobalOptions, args []string, term ui.Ter case "snapshot": sn, _, err := restic.FindSnapshot(ctx, repo, repo, args[1]) if err != nil { - return errors.Fatalf("could not find snapshot: %v\n", err) + return errors.Fatalf("could not find snapshot: %v", err) } buf, err := json.MarshalIndent(sn, "", " ") @@ -195,7 +195,7 @@ func runCat(ctx context.Context, gopts GlobalOptions, args []string, term ui.Ter case "tree": sn, subfolder, err := restic.FindSnapshot(ctx, repo, repo, args[1]) if err != nil { - return errors.Fatalf("could not find snapshot: %v\n", err) + return errors.Fatalf("could not find snapshot: %v", err) } bar := newIndexTerminalProgress(printer) diff --git a/cmd/restic/cmd_init.go b/cmd/restic/cmd_init.go index 6e3477c28..b1bfc637e 100644 --- a/cmd/restic/cmd_init.go +++ b/cmd/restic/cmd_init.go @@ -102,7 +102,7 @@ func runInit(ctx context.Context, opts InitOptions, gopts GlobalOptions, args [] be, err := create(ctx, gopts.Repo, gopts, gopts.extended, printer) if err != nil { - return errors.Fatalf("create repository at %s failed: %v\n", location.StripPassword(gopts.backends, gopts.Repo), err) + return errors.Fatalf("create repository at %s failed: %v", location.StripPassword(gopts.backends, gopts.Repo), err) } s, err := repository.New(be, repository.Options{ @@ -115,7 +115,7 @@ func runInit(ctx context.Context, opts InitOptions, gopts GlobalOptions, args [] err = s.Init(ctx, version, gopts.password, chunkerPolynomial) if err != nil { - return errors.Fatalf("create key in repository at %s failed: %v\n", location.StripPassword(gopts.backends, gopts.Repo), err) + return errors.Fatalf("create key in repository at %s failed: %v", location.StripPassword(gopts.backends, gopts.Repo), err) } if !gopts.JSON { diff --git a/cmd/restic/cmd_key_add.go b/cmd/restic/cmd_key_add.go index 13785d43b..1c3fc04f6 100644 --- a/cmd/restic/cmd_key_add.go +++ b/cmd/restic/cmd_key_add.go @@ -79,7 +79,7 @@ func addKey(ctx context.Context, repo *repository.Repository, gopts GlobalOption id, err := repository.AddKey(ctx, repo, pw, opts.Username, opts.Hostname, repo.Key()) if err != nil { - return errors.Fatalf("creating new key failed: %v\n", err) + return errors.Fatalf("creating new key failed: %v", err) } err = switchToNewKeyAndRemoveIfBroken(ctx, repo, id, pw) diff --git a/cmd/restic/cmd_key_passwd.go b/cmd/restic/cmd_key_passwd.go index 3e1be711b..798a9fbaa 100644 --- a/cmd/restic/cmd_key_passwd.go +++ b/cmd/restic/cmd_key_passwd.go @@ -74,7 +74,7 @@ func changePassword(ctx context.Context, repo *repository.Repository, gopts Glob id, err := repository.AddKey(ctx, repo, pw, "", "", repo.Key()) if err != nil { - return errors.Fatalf("creating new key failed: %v\n", err) + return errors.Fatalf("creating new key failed: %v", err) } oldID := repo.KeyID() diff --git a/cmd/restic/cmd_restore.go b/cmd/restic/cmd_restore.go index 915829b0c..888226c8e 100644 --- a/cmd/restic/cmd_restore.go +++ b/cmd/restic/cmd_restore.go @@ -251,7 +251,7 @@ func runRestore(ctx context.Context, opts RestoreOptions, gopts GlobalOptions, progress.Finish() if totalErrors > 0 { - return errors.Fatalf("There were %d errors\n", totalErrors) + return errors.Fatalf("There were %d errors", totalErrors) } if opts.Verify { @@ -266,7 +266,7 @@ func runRestore(ctx context.Context, opts RestoreOptions, gopts GlobalOptions, return err } if totalErrors > 0 { - return errors.Fatalf("There were %d errors\n", totalErrors) + return errors.Fatalf("There were %d errors", totalErrors) } if !gopts.JSON { diff --git a/cmd/restic/cmd_rewrite.go b/cmd/restic/cmd_rewrite.go index b2d771bb4..45ec3c13b 100644 --- a/cmd/restic/cmd_rewrite.go +++ b/cmd/restic/cmd_rewrite.go @@ -93,7 +93,7 @@ func (sma snapshotMetadataArgs) convert() (*snapshotMetadata, error) { if sma.Time != "" { t, err := time.ParseInLocation(TimeFormat, sma.Time, time.Local) if err != nil { - return nil, errors.Fatalf("error in time option: %v\n", err) + return nil, errors.Fatalf("error in time option: %v", err) } timeStamp = &t } From d491c1bdbf11f84ed0d7a5428296b3f618afaca4 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Wed, 24 Sep 2025 22:11:54 +0200 Subject: [PATCH 2/2] use errors.Fatalf instead of custom formatting --- cmd/restic/global.go | 2 +- internal/fs/fs_reader_command.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/restic/global.go b/cmd/restic/global.go index 269a5fd04..6838b1227 100644 --- a/cmd/restic/global.go +++ b/cmd/restic/global.go @@ -171,7 +171,7 @@ func (opts *GlobalOptions) PreRun(needsPassword bool) error { } pwd, err := resolvePassword(opts, "RESTIC_PASSWORD") if err != nil { - return errors.Fatal(fmt.Sprintf("Resolving password failed: %v\n", err)) + return errors.Fatalf("Resolving password failed: %v", err) } opts.password = pwd return nil diff --git a/internal/fs/fs_reader_command.go b/internal/fs/fs_reader_command.go index 2fa4375dd..9e6674e8f 100644 --- a/internal/fs/fs_reader_command.go +++ b/internal/fs/fs_reader_command.go @@ -87,7 +87,7 @@ func (fp *CommandReader) wait() error { err := fp.cmd.Wait() if err != nil { // Use a fatal error to abort the snapshot. - return errors.Fatal(fmt.Errorf("command failed: %w", err).Error()) + return errors.Fatalf("command failed: %v", err) } return nil }