forked from TrueCloudLab/restic
f92ecf13c9
github.com/pkg/errors is no longer getting updates, because Go 1.13 went with the more flexible errors.{As,Is} function. Use those instead: errors from pkg/errors already support the Unwrap interface used by 1.13 error handling. Also: * check for io.EOF with a straight ==. That value should not be wrapped, and the chunker (whose error is checked in the cases changed) does not wrap it. * Give custom Error methods pointer receivers, so there's no ambiguity when type-switching since the value type will no longer implement error. * Make restic.ErrAlreadyLocked private, and rename it to alreadyLockedError to match the stdlib convention that error type names end in Error. * Same with rest.ErrIsNotExist => rest.notExistError. * Make s3.Backend.IsAccessDenied a private function.
57 lines
1.4 KiB
Go
57 lines
1.4 KiB
Go
package errors
|
|
|
|
import (
|
|
"net/url"
|
|
|
|
"github.com/cenkalti/backoff/v4"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
// 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
|
|
|
|
// WithMessage annotates err with a new message. If err is nil, WithMessage
|
|
// returns nil.
|
|
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 Is(x, y error) bool { return errors.Is(x, y) }
|