mirror of
https://github.com/restic/restic.git
synced 2025-12-03 20:51:47 +00:00
errors: Drop Cause in favor of Go 1.13 error handling
The only use cases in the code were in errors.IsFatal, backend/b2, which needs a workaround, and backend.ParseLayout. The last of these requires all backends to implement error unwrapping in IsNotExist. All backends except gs already did that.
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package errors
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// fatalError is an error that should be printed to the user, then the program
|
||||
// should exit with an error code.
|
||||
@@ -10,31 +13,19 @@ func (e fatalError) Error() string {
|
||||
return string(e)
|
||||
}
|
||||
|
||||
func (e fatalError) Fatal() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// Fataler is an error which should be printed to the user directly.
|
||||
// Afterwards, the program should exit with an error.
|
||||
type Fataler interface {
|
||||
Fatal() bool
|
||||
}
|
||||
|
||||
// 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()
|
||||
var fatal fatalError
|
||||
return errors.As(err, &fatal)
|
||||
}
|
||||
|
||||
// Fatal returns a wrapped error which implements the Fataler interface.
|
||||
// Fatal returns an error that is marked fatal.
|
||||
func Fatal(s string) error {
|
||||
return Wrap(fatalError(s), "Fatal")
|
||||
}
|
||||
|
||||
// Fatalf returns an error which implements the Fataler interface.
|
||||
// Fatalf returns an error that is marked fatal.
|
||||
func Fatalf(s string, data ...interface{}) error {
|
||||
return Wrap(fatalError(fmt.Sprintf(s, data...)), "Fatal")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user