2018-02-05 21:05:59 +00:00
|
|
|
package errdefs // import "github.com/docker/docker/errdefs"
|
2017-11-29 04:09:37 +00:00
|
|
|
|
|
|
|
import "context"
|
|
|
|
|
|
|
|
type errNotFound struct{ error }
|
|
|
|
|
|
|
|
func (errNotFound) NotFound() {}
|
|
|
|
|
|
|
|
func (e errNotFound) Cause() error {
|
|
|
|
return e.error
|
|
|
|
}
|
|
|
|
|
2020-11-15 19:41:37 +00:00
|
|
|
func (e errNotFound) Unwrap() error {
|
|
|
|
return e.error
|
|
|
|
}
|
|
|
|
|
2017-11-29 04:09:37 +00:00
|
|
|
// NotFound is a helper to create an error of the class with the same name from any error type
|
|
|
|
func NotFound(err error) error {
|
2018-12-30 14:26:23 +00:00
|
|
|
if err == nil || IsNotFound(err) {
|
|
|
|
return err
|
2017-11-29 04:09:37 +00:00
|
|
|
}
|
|
|
|
return errNotFound{err}
|
|
|
|
}
|
|
|
|
|
|
|
|
type errInvalidParameter struct{ error }
|
|
|
|
|
|
|
|
func (errInvalidParameter) InvalidParameter() {}
|
|
|
|
|
|
|
|
func (e errInvalidParameter) Cause() error {
|
|
|
|
return e.error
|
|
|
|
}
|
|
|
|
|
2020-11-15 19:41:37 +00:00
|
|
|
func (e errInvalidParameter) Unwrap() error {
|
|
|
|
return e.error
|
|
|
|
}
|
|
|
|
|
2017-11-29 04:09:37 +00:00
|
|
|
// InvalidParameter is a helper to create an error of the class with the same name from any error type
|
|
|
|
func InvalidParameter(err error) error {
|
2018-12-30 14:26:23 +00:00
|
|
|
if err == nil || IsInvalidParameter(err) {
|
|
|
|
return err
|
2017-11-29 04:09:37 +00:00
|
|
|
}
|
|
|
|
return errInvalidParameter{err}
|
|
|
|
}
|
|
|
|
|
|
|
|
type errConflict struct{ error }
|
|
|
|
|
|
|
|
func (errConflict) Conflict() {}
|
|
|
|
|
|
|
|
func (e errConflict) Cause() error {
|
|
|
|
return e.error
|
|
|
|
}
|
|
|
|
|
2020-11-15 19:41:37 +00:00
|
|
|
func (e errConflict) Unwrap() error {
|
|
|
|
return e.error
|
|
|
|
}
|
|
|
|
|
2017-11-29 04:09:37 +00:00
|
|
|
// Conflict is a helper to create an error of the class with the same name from any error type
|
|
|
|
func Conflict(err error) error {
|
2018-12-30 14:26:23 +00:00
|
|
|
if err == nil || IsConflict(err) {
|
|
|
|
return err
|
2017-11-29 04:09:37 +00:00
|
|
|
}
|
|
|
|
return errConflict{err}
|
|
|
|
}
|
|
|
|
|
|
|
|
type errUnauthorized struct{ error }
|
|
|
|
|
|
|
|
func (errUnauthorized) Unauthorized() {}
|
|
|
|
|
|
|
|
func (e errUnauthorized) Cause() error {
|
|
|
|
return e.error
|
|
|
|
}
|
|
|
|
|
2020-11-15 19:41:37 +00:00
|
|
|
func (e errUnauthorized) Unwrap() error {
|
|
|
|
return e.error
|
|
|
|
}
|
|
|
|
|
2017-11-29 04:09:37 +00:00
|
|
|
// Unauthorized is a helper to create an error of the class with the same name from any error type
|
|
|
|
func Unauthorized(err error) error {
|
2018-12-30 14:26:23 +00:00
|
|
|
if err == nil || IsUnauthorized(err) {
|
|
|
|
return err
|
2017-11-29 04:09:37 +00:00
|
|
|
}
|
|
|
|
return errUnauthorized{err}
|
|
|
|
}
|
|
|
|
|
|
|
|
type errUnavailable struct{ error }
|
|
|
|
|
|
|
|
func (errUnavailable) Unavailable() {}
|
|
|
|
|
|
|
|
func (e errUnavailable) Cause() error {
|
|
|
|
return e.error
|
|
|
|
}
|
|
|
|
|
2020-11-15 19:41:37 +00:00
|
|
|
func (e errUnavailable) Unwrap() error {
|
|
|
|
return e.error
|
|
|
|
}
|
|
|
|
|
2017-11-29 04:09:37 +00:00
|
|
|
// Unavailable is a helper to create an error of the class with the same name from any error type
|
|
|
|
func Unavailable(err error) error {
|
2018-12-30 14:26:23 +00:00
|
|
|
if err == nil || IsUnavailable(err) {
|
|
|
|
return err
|
2018-12-30 14:18:57 +00:00
|
|
|
}
|
2017-11-29 04:09:37 +00:00
|
|
|
return errUnavailable{err}
|
|
|
|
}
|
|
|
|
|
|
|
|
type errForbidden struct{ error }
|
|
|
|
|
|
|
|
func (errForbidden) Forbidden() {}
|
|
|
|
|
|
|
|
func (e errForbidden) Cause() error {
|
|
|
|
return e.error
|
|
|
|
}
|
|
|
|
|
2020-11-15 19:41:37 +00:00
|
|
|
func (e errForbidden) Unwrap() error {
|
|
|
|
return e.error
|
|
|
|
}
|
|
|
|
|
2017-11-29 04:09:37 +00:00
|
|
|
// Forbidden is a helper to create an error of the class with the same name from any error type
|
|
|
|
func Forbidden(err error) error {
|
2018-12-30 14:26:23 +00:00
|
|
|
if err == nil || IsForbidden(err) {
|
|
|
|
return err
|
2017-11-29 04:09:37 +00:00
|
|
|
}
|
|
|
|
return errForbidden{err}
|
|
|
|
}
|
|
|
|
|
|
|
|
type errSystem struct{ error }
|
|
|
|
|
|
|
|
func (errSystem) System() {}
|
|
|
|
|
|
|
|
func (e errSystem) Cause() error {
|
|
|
|
return e.error
|
|
|
|
}
|
|
|
|
|
2020-11-15 19:41:37 +00:00
|
|
|
func (e errSystem) Unwrap() error {
|
|
|
|
return e.error
|
|
|
|
}
|
|
|
|
|
2017-11-29 04:09:37 +00:00
|
|
|
// System is a helper to create an error of the class with the same name from any error type
|
|
|
|
func System(err error) error {
|
2018-12-30 14:26:23 +00:00
|
|
|
if err == nil || IsSystem(err) {
|
|
|
|
return err
|
2017-11-29 04:09:37 +00:00
|
|
|
}
|
|
|
|
return errSystem{err}
|
|
|
|
}
|
|
|
|
|
|
|
|
type errNotModified struct{ error }
|
|
|
|
|
|
|
|
func (errNotModified) NotModified() {}
|
|
|
|
|
|
|
|
func (e errNotModified) Cause() error {
|
|
|
|
return e.error
|
|
|
|
}
|
|
|
|
|
2020-11-15 19:41:37 +00:00
|
|
|
func (e errNotModified) Unwrap() error {
|
|
|
|
return e.error
|
|
|
|
}
|
|
|
|
|
2017-11-29 04:09:37 +00:00
|
|
|
// NotModified is a helper to create an error of the class with the same name from any error type
|
|
|
|
func NotModified(err error) error {
|
2018-12-30 14:26:23 +00:00
|
|
|
if err == nil || IsNotModified(err) {
|
|
|
|
return err
|
2017-11-29 04:09:37 +00:00
|
|
|
}
|
|
|
|
return errNotModified{err}
|
|
|
|
}
|
|
|
|
|
|
|
|
type errNotImplemented struct{ error }
|
|
|
|
|
|
|
|
func (errNotImplemented) NotImplemented() {}
|
|
|
|
|
|
|
|
func (e errNotImplemented) Cause() error {
|
|
|
|
return e.error
|
|
|
|
}
|
|
|
|
|
2020-11-15 19:41:37 +00:00
|
|
|
func (e errNotImplemented) Unwrap() error {
|
|
|
|
return e.error
|
|
|
|
}
|
|
|
|
|
2017-11-29 04:09:37 +00:00
|
|
|
// NotImplemented is a helper to create an error of the class with the same name from any error type
|
|
|
|
func NotImplemented(err error) error {
|
2018-12-30 14:26:23 +00:00
|
|
|
if err == nil || IsNotImplemented(err) {
|
|
|
|
return err
|
2017-11-29 04:09:37 +00:00
|
|
|
}
|
|
|
|
return errNotImplemented{err}
|
|
|
|
}
|
|
|
|
|
|
|
|
type errUnknown struct{ error }
|
|
|
|
|
|
|
|
func (errUnknown) Unknown() {}
|
|
|
|
|
|
|
|
func (e errUnknown) Cause() error {
|
|
|
|
return e.error
|
|
|
|
}
|
|
|
|
|
2020-11-15 19:41:37 +00:00
|
|
|
func (e errUnknown) Unwrap() error {
|
|
|
|
return e.error
|
|
|
|
}
|
|
|
|
|
2017-11-29 04:09:37 +00:00
|
|
|
// Unknown is a helper to create an error of the class with the same name from any error type
|
|
|
|
func Unknown(err error) error {
|
2018-12-30 14:26:23 +00:00
|
|
|
if err == nil || IsUnknown(err) {
|
|
|
|
return err
|
2017-11-29 04:09:37 +00:00
|
|
|
}
|
|
|
|
return errUnknown{err}
|
|
|
|
}
|
|
|
|
|
|
|
|
type errCancelled struct{ error }
|
|
|
|
|
|
|
|
func (errCancelled) Cancelled() {}
|
|
|
|
|
|
|
|
func (e errCancelled) Cause() error {
|
|
|
|
return e.error
|
|
|
|
}
|
|
|
|
|
2020-11-15 19:41:37 +00:00
|
|
|
func (e errCancelled) Unwrap() error {
|
|
|
|
return e.error
|
|
|
|
}
|
|
|
|
|
2017-11-29 04:09:37 +00:00
|
|
|
// Cancelled is a helper to create an error of the class with the same name from any error type
|
|
|
|
func Cancelled(err error) error {
|
2018-12-30 14:26:23 +00:00
|
|
|
if err == nil || IsCancelled(err) {
|
|
|
|
return err
|
2017-11-29 04:09:37 +00:00
|
|
|
}
|
|
|
|
return errCancelled{err}
|
|
|
|
}
|
|
|
|
|
|
|
|
type errDeadline struct{ error }
|
|
|
|
|
|
|
|
func (errDeadline) DeadlineExceeded() {}
|
|
|
|
|
|
|
|
func (e errDeadline) Cause() error {
|
|
|
|
return e.error
|
|
|
|
}
|
|
|
|
|
2020-11-15 19:41:37 +00:00
|
|
|
func (e errDeadline) Unwrap() error {
|
|
|
|
return e.error
|
|
|
|
}
|
|
|
|
|
2017-11-29 04:09:37 +00:00
|
|
|
// Deadline is a helper to create an error of the class with the same name from any error type
|
|
|
|
func Deadline(err error) error {
|
2018-12-30 14:26:23 +00:00
|
|
|
if err == nil || IsDeadline(err) {
|
|
|
|
return err
|
2017-11-29 04:09:37 +00:00
|
|
|
}
|
|
|
|
return errDeadline{err}
|
|
|
|
}
|
|
|
|
|
|
|
|
type errDataLoss struct{ error }
|
|
|
|
|
|
|
|
func (errDataLoss) DataLoss() {}
|
|
|
|
|
|
|
|
func (e errDataLoss) Cause() error {
|
|
|
|
return e.error
|
|
|
|
}
|
|
|
|
|
2020-11-15 19:41:37 +00:00
|
|
|
func (e errDataLoss) Unwrap() error {
|
|
|
|
return e.error
|
|
|
|
}
|
|
|
|
|
2017-11-29 04:09:37 +00:00
|
|
|
// DataLoss is a helper to create an error of the class with the same name from any error type
|
|
|
|
func DataLoss(err error) error {
|
2018-12-30 14:26:23 +00:00
|
|
|
if err == nil || IsDataLoss(err) {
|
|
|
|
return err
|
2017-11-29 04:09:37 +00:00
|
|
|
}
|
|
|
|
return errDataLoss{err}
|
|
|
|
}
|
|
|
|
|
|
|
|
// FromContext returns the error class from the passed in context
|
|
|
|
func FromContext(ctx context.Context) error {
|
|
|
|
e := ctx.Err()
|
|
|
|
if e == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if e == context.Canceled {
|
|
|
|
return Cancelled(e)
|
|
|
|
}
|
|
|
|
if e == context.DeadlineExceeded {
|
|
|
|
return Deadline(e)
|
|
|
|
}
|
|
|
|
return Unknown(e)
|
|
|
|
}
|