2018-02-05 16:05:59 -05:00
|
|
|
package errdefs // import "github.com/docker/docker/errdefs"
|
2017-07-19 10:20:13 -04:00
|
|
|
|
|
|
|
type causer interface {
|
|
|
|
Cause() error
|
|
|
|
}
|
|
|
|
|
|
|
|
func getImplementer(err error) error {
|
|
|
|
switch e := err.(type) {
|
|
|
|
case
|
|
|
|
ErrNotFound,
|
|
|
|
ErrInvalidParameter,
|
|
|
|
ErrConflict,
|
|
|
|
ErrUnauthorized,
|
|
|
|
ErrUnavailable,
|
|
|
|
ErrForbidden,
|
|
|
|
ErrSystem,
|
|
|
|
ErrNotModified,
|
|
|
|
ErrNotImplemented,
|
2017-11-28 23:09:37 -05:00
|
|
|
ErrCancelled,
|
|
|
|
ErrDeadline,
|
|
|
|
ErrDataLoss,
|
2017-07-19 10:20:13 -04:00
|
|
|
ErrUnknown:
|
2018-03-05 11:16:25 -05:00
|
|
|
return err
|
2017-07-19 10:20:13 -04:00
|
|
|
case causer:
|
|
|
|
return getImplementer(e.Cause())
|
|
|
|
default:
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-31 10:22:07 -04:00
|
|
|
// IsNotFound returns if the passed in error is an ErrNotFound
|
2017-07-19 10:20:13 -04:00
|
|
|
func IsNotFound(err error) bool {
|
|
|
|
_, ok := getImplementer(err).(ErrNotFound)
|
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsInvalidParameter returns if the passed in error is an ErrInvalidParameter
|
|
|
|
func IsInvalidParameter(err error) bool {
|
|
|
|
_, ok := getImplementer(err).(ErrInvalidParameter)
|
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
2017-10-31 10:22:07 -04:00
|
|
|
// IsConflict returns if the passed in error is an ErrConflict
|
2017-07-19 10:20:13 -04:00
|
|
|
func IsConflict(err error) bool {
|
|
|
|
_, ok := getImplementer(err).(ErrConflict)
|
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
2018-05-17 08:09:19 -04:00
|
|
|
// IsUnauthorized returns if the passed in error is an ErrUnauthorized
|
2017-07-19 10:20:13 -04:00
|
|
|
func IsUnauthorized(err error) bool {
|
|
|
|
_, ok := getImplementer(err).(ErrUnauthorized)
|
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsUnavailable returns if the passed in error is an ErrUnavailable
|
|
|
|
func IsUnavailable(err error) bool {
|
|
|
|
_, ok := getImplementer(err).(ErrUnavailable)
|
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
2017-10-31 10:22:07 -04:00
|
|
|
// IsForbidden returns if the passed in error is an ErrForbidden
|
2017-07-19 10:20:13 -04:00
|
|
|
func IsForbidden(err error) bool {
|
|
|
|
_, ok := getImplementer(err).(ErrForbidden)
|
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
2017-10-31 10:22:07 -04:00
|
|
|
// IsSystem returns if the passed in error is an ErrSystem
|
2017-07-19 10:20:13 -04:00
|
|
|
func IsSystem(err error) bool {
|
|
|
|
_, ok := getImplementer(err).(ErrSystem)
|
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsNotModified returns if the passed in error is a NotModified error
|
|
|
|
func IsNotModified(err error) bool {
|
|
|
|
_, ok := getImplementer(err).(ErrNotModified)
|
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
2017-10-31 10:22:07 -04:00
|
|
|
// IsNotImplemented returns if the passed in error is an ErrNotImplemented
|
2017-07-19 10:20:13 -04:00
|
|
|
func IsNotImplemented(err error) bool {
|
|
|
|
_, ok := getImplementer(err).(ErrNotImplemented)
|
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsUnknown returns if the passed in error is an ErrUnknown
|
|
|
|
func IsUnknown(err error) bool {
|
|
|
|
_, ok := getImplementer(err).(ErrUnknown)
|
|
|
|
return ok
|
|
|
|
}
|
2017-11-28 23:09:37 -05:00
|
|
|
|
|
|
|
// IsCancelled returns if the passed in error is an ErrCancelled
|
|
|
|
func IsCancelled(err error) bool {
|
|
|
|
_, ok := getImplementer(err).(ErrCancelled)
|
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsDeadline returns if the passed in error is an ErrDeadline
|
|
|
|
func IsDeadline(err error) bool {
|
|
|
|
_, ok := getImplementer(err).(ErrDeadline)
|
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsDataLoss returns if the passed in error is an ErrDataLoss
|
|
|
|
func IsDataLoss(err error) bool {
|
|
|
|
_, ok := getImplementer(err).(ErrDataLoss)
|
|
|
|
return ok
|
|
|
|
}
|