mirror of
https://github.com/restic/restic.git
synced 2025-08-23 12:57:56 +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,9 +1,8 @@
|
||||
package errors
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
stderrors "errors"
|
||||
|
||||
"github.com/cenkalti/backoff/v4"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@@ -29,29 +28,10 @@ var WithMessage = errors.WithMessage
|
||||
|
||||
var WithStack = errors.WithStack
|
||||
|
||||
// Cause returns the cause of an error. It will also unwrap certain errors,
|
||||
// e.g. *url.Error returned by the net/http client.
|
||||
func Cause(err error) error {
|
||||
type Causer interface {
|
||||
Cause() error
|
||||
}
|
||||
|
||||
for {
|
||||
switch e := err.(type) {
|
||||
case Causer: // github.com/pkg/errors
|
||||
err = e.Cause()
|
||||
case *backoff.PermanentError:
|
||||
err = e.Err
|
||||
case *url.Error:
|
||||
err = e.Err
|
||||
default:
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Go 1.13-style error handling.
|
||||
|
||||
func As(err error, tgt interface{}) bool { return errors.As(err, tgt) }
|
||||
func As(err error, tgt interface{}) bool { return stderrors.As(err, tgt) }
|
||||
|
||||
func Is(x, y error) bool { return errors.Is(x, y) }
|
||||
func Is(x, y error) bool { return stderrors.Is(x, y) }
|
||||
|
||||
func Unwrap(err error) error { return stderrors.Unwrap(err) }
|
||||
|
Reference in New Issue
Block a user