mirror of
https://github.com/octoleo/restic.git
synced 2024-11-16 18:15:20 +00:00
07e5c38361
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.
32 lines
726 B
Go
32 lines
726 B
Go
package errors
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
)
|
|
|
|
// fatalError is an error that should be printed to the user, then the program
|
|
// should exit with an error code.
|
|
type fatalError string
|
|
|
|
func (e fatalError) Error() string {
|
|
return string(e)
|
|
}
|
|
|
|
// 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 {
|
|
var fatal fatalError
|
|
return errors.As(err, &fatal)
|
|
}
|
|
|
|
// Fatal returns an error that is marked fatal.
|
|
func Fatal(s string) error {
|
|
return Wrap(fatalError(s), "Fatal")
|
|
}
|
|
|
|
// Fatalf returns an error that is marked fatal.
|
|
func Fatalf(s string, data ...interface{}) error {
|
|
return Wrap(fatalError(fmt.Sprintf(s, data...)), "Fatal")
|
|
}
|