2016-09-01 20:17:37 +00:00
|
|
|
package errors
|
2016-08-28 20:19:48 +00:00
|
|
|
|
2022-10-08 10:37:18 +00:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
)
|
2016-08-28 20:19:48 +00:00
|
|
|
|
|
|
|
// 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 {
|
2022-10-08 10:37:18 +00:00
|
|
|
var fatal fatalError
|
|
|
|
return errors.As(err, &fatal)
|
2016-08-28 20:19:48 +00:00
|
|
|
}
|
|
|
|
|
2022-10-08 10:37:18 +00:00
|
|
|
// Fatal returns an error that is marked fatal.
|
2016-08-28 20:19:48 +00:00
|
|
|
func Fatal(s string) error {
|
2016-09-25 16:27:03 +00:00
|
|
|
return Wrap(fatalError(s), "Fatal")
|
2016-08-28 20:19:48 +00:00
|
|
|
}
|
|
|
|
|
2022-10-08 10:37:18 +00:00
|
|
|
// Fatalf returns an error that is marked fatal.
|
2016-08-28 20:19:48 +00:00
|
|
|
func Fatalf(s string, data ...interface{}) error {
|
2018-01-06 22:11:54 +00:00
|
|
|
return Wrap(fatalError(fmt.Sprintf(s, data...)), "Fatal")
|
2016-08-28 20:19:48 +00:00
|
|
|
}
|