2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-29 13:22:43 +00:00
restic/internal/errors/errors.go

56 lines
1.3 KiB
Go
Raw Normal View History

2016-09-01 20:17:37 +00:00
package errors
2018-01-23 20:40:51 +00:00
import (
"net/url"
2016-09-01 20:17:37 +00:00
"github.com/cenkalti/backoff/v4"
2018-01-23 20:40:51 +00:00
"github.com/pkg/errors"
)
2016-09-01 20:17:37 +00:00
// New creates a new error based on message. Wrapped so that this package does
// not appear in the stack trace.
var New = errors.New
2016-09-01 20:17:37 +00:00
// 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
2016-09-01 20:17:37 +00:00
// 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
2017-02-11 13:22:04 +00:00
// Wrapf returns an error annotating err with the format specifier. If err is
// nil, Wrapf returns nil.
var Wrapf = errors.Wrapf
2018-01-23 20:40:51 +00:00
// WithMessage annotates err with a new message. If err is nil, WithMessage
// returns nil.
var WithMessage = errors.WithMessage
var WithStack = errors.WithStack
2018-01-23 20:40:51 +00:00
// 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
2018-01-23 20:40:51 +00:00
}
}
}
// Go 1.13-style error handling.
func Is(x, y error) bool { return errors.Is(x, y) }