mirror of
https://github.com/octoleo/restic.git
synced 2024-12-22 02:48:55 +00:00
errors: Ensure that errors.IsFatal(errors.Fatal("err")) == true
This fixes a few cases where restic output "Fatal: Fatal: [...]"
This commit is contained in:
parent
a08b95c497
commit
2e1613d4c6
@ -102,7 +102,7 @@ func main() {
|
||||
fmt.Fprintf(os.Stderr, "%v\nthe `unlock` command can be used to remove stale locks\n", err)
|
||||
case err == ErrInvalidSourceData:
|
||||
fmt.Fprintf(os.Stderr, "Warning: %v\n", err)
|
||||
case errors.IsFatal(errors.Cause(err)):
|
||||
case errors.IsFatal(err):
|
||||
fmt.Fprintf(os.Stderr, "%v\n", err)
|
||||
case err != nil:
|
||||
fmt.Fprintf(os.Stderr, "%+v\n", err)
|
||||
|
@ -23,6 +23,8 @@ type Fataler interface {
|
||||
// IsFatal returns true if err is a fatal message that should be printed to the
|
||||
// user. Then, the program should exit.
|
||||
func IsFatal(err error) bool {
|
||||
// unwrap "Wrap" method
|
||||
err = Cause(err)
|
||||
e, ok := err.(Fataler)
|
||||
return ok && e.Fatal()
|
||||
}
|
||||
|
22
internal/errors/fatal_test.go
Normal file
22
internal/errors/fatal_test.go
Normal file
@ -0,0 +1,22 @@
|
||||
package errors_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/restic/restic/internal/errors"
|
||||
)
|
||||
|
||||
func TestFatal(t *testing.T) {
|
||||
for _, v := range []struct {
|
||||
err error
|
||||
expected bool
|
||||
}{
|
||||
{errors.Fatal("broken"), true},
|
||||
{errors.Fatalf("broken %d", 42), true},
|
||||
{errors.New("error"), false},
|
||||
} {
|
||||
if errors.IsFatal(v.err) != v.expected {
|
||||
t.Fatalf("IsFatal for %q, expected: %v, got: %v", v.err, v.expected, errors.IsFatal(v.err))
|
||||
}
|
||||
}
|
||||
}
|
@ -78,7 +78,7 @@ func LoadConfig(ctx context.Context, r JSONUnpackedLoader) (Config, error) {
|
||||
}
|
||||
|
||||
if cfg.Version != RepoVersion {
|
||||
return Config{}, errors.New("unsupported repository version")
|
||||
return Config{}, errors.Errorf("unsupported repository version %v", cfg.Version)
|
||||
}
|
||||
|
||||
if checkPolynomial {
|
||||
|
Loading…
Reference in New Issue
Block a user