mirror of
https://github.com/restic/restic.git
synced 2025-08-12 18:01:08 +00:00
Moves files
This commit is contained in:
2
internal/errors/doc.go
Normal file
2
internal/errors/doc.go
Normal file
@@ -0,0 +1,2 @@
|
||||
// Package errors provides custom error types used within restic.
|
||||
package errors
|
38
internal/errors/fatal.go
Normal file
38
internal/errors/fatal.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package errors
|
||||
|
||||
import "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)
|
||||
}
|
||||
|
||||
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 {
|
||||
e, ok := err.(Fataler)
|
||||
return ok && e.Fatal()
|
||||
}
|
||||
|
||||
// Fatal returns a wrapped error which implements the Fataler interface.
|
||||
func Fatal(s string) error {
|
||||
return Wrap(fatalError(s), "Fatal")
|
||||
}
|
||||
|
||||
// Fatalf returns an error which implements the Fataler interface.
|
||||
func Fatalf(s string, data ...interface{}) error {
|
||||
return fatalError(fmt.Sprintf(s, data...))
|
||||
}
|
24
internal/errors/wrap.go
Normal file
24
internal/errors/wrap.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package errors
|
||||
|
||||
import "github.com/pkg/errors"
|
||||
|
||||
// Cause returns the cause of an error.
|
||||
func Cause(err error) error {
|
||||
return errors.Cause(err)
|
||||
}
|
||||
|
||||
// New creates a new error based on message. Wrapped so that this package does
|
||||
// not appear in the stack trace.
|
||||
var New = errors.New
|
||||
|
||||
// Errorf creates an error based on a format string and values. Wrapped so that
|
||||
// this package does not appear in the stack trace.
|
||||
var Errorf = errors.Errorf
|
||||
|
||||
// Wrap wraps an error retrieved from outside of restic. Wrapped so that this
|
||||
// package does not appear in the stack trace.
|
||||
var Wrap = errors.Wrap
|
||||
|
||||
// Wrapf returns an error annotating err with the format specifier. If err is
|
||||
// nil, Wrapf returns nil.
|
||||
var Wrapf = errors.Wrapf
|
Reference in New Issue
Block a user