mirror of
https://github.com/moby/moby.git
synced 2026-01-11 02:31:44 +00:00
Use containerd errdefs for error checks
Signed-off-by: Derek McGowan <derek@mcg.dev>
This commit is contained in:
127
errdefs/is.go
127
errdefs/is.go
@@ -3,119 +3,74 @@ package errdefs
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
cerrdefs "github.com/containerd/errdefs"
|
||||
)
|
||||
|
||||
type causer interface {
|
||||
Cause() error
|
||||
}
|
||||
|
||||
type wrapErr interface {
|
||||
Unwrap() error
|
||||
}
|
||||
|
||||
func getImplementer(err error) error {
|
||||
switch e := err.(type) {
|
||||
case
|
||||
ErrNotFound,
|
||||
ErrInvalidParameter,
|
||||
ErrConflict,
|
||||
ErrUnauthorized,
|
||||
ErrUnavailable,
|
||||
ErrForbidden,
|
||||
ErrSystem,
|
||||
ErrNotModified,
|
||||
ErrNotImplemented,
|
||||
ErrCancelled,
|
||||
ErrDeadline,
|
||||
ErrDataLoss,
|
||||
ErrUnknown:
|
||||
return err
|
||||
case causer:
|
||||
return getImplementer(e.Cause())
|
||||
case wrapErr:
|
||||
return getImplementer(e.Unwrap())
|
||||
default:
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// IsNotFound returns if the passed in error is an [ErrNotFound],
|
||||
func IsNotFound(err error) bool {
|
||||
_, ok := getImplementer(err).(ErrNotFound)
|
||||
return ok
|
||||
}
|
||||
//
|
||||
// Deprecated: use containerd [cerrdefs.IsNotFound]
|
||||
var IsNotFound = cerrdefs.IsNotFound
|
||||
|
||||
// IsInvalidParameter returns if the passed in error is an [ErrInvalidParameter].
|
||||
func IsInvalidParameter(err error) bool {
|
||||
_, ok := getImplementer(err).(ErrInvalidParameter)
|
||||
return ok
|
||||
}
|
||||
//
|
||||
// Deprecated: use containerd [cerrdefs.IsInvalidArgument]
|
||||
var IsInvalidParameter = cerrdefs.IsInvalidArgument
|
||||
|
||||
// IsConflict returns if the passed in error is an [ErrConflict].
|
||||
func IsConflict(err error) bool {
|
||||
_, ok := getImplementer(err).(ErrConflict)
|
||||
return ok
|
||||
}
|
||||
//
|
||||
// Deprecated: use containerd [cerrdefs.IsConflict]
|
||||
var IsConflict = cerrdefs.IsConflict
|
||||
|
||||
// IsUnauthorized returns if the passed in error is an [ErrUnauthorized].
|
||||
func IsUnauthorized(err error) bool {
|
||||
_, ok := getImplementer(err).(ErrUnauthorized)
|
||||
return ok
|
||||
}
|
||||
//
|
||||
// Deprecated: use containerd [cerrdefs.IsUnauthorized]
|
||||
var IsUnauthorized = cerrdefs.IsUnauthorized
|
||||
|
||||
// IsUnavailable returns if the passed in error is an [ErrUnavailable].
|
||||
func IsUnavailable(err error) bool {
|
||||
_, ok := getImplementer(err).(ErrUnavailable)
|
||||
return ok
|
||||
}
|
||||
//
|
||||
// Deprecated: use containerd [cerrdefs.IsUnavailable]
|
||||
var IsUnavailable = cerrdefs.IsUnavailable
|
||||
|
||||
// IsForbidden returns if the passed in error is an [ErrForbidden].
|
||||
func IsForbidden(err error) bool {
|
||||
_, ok := getImplementer(err).(ErrForbidden)
|
||||
return ok
|
||||
}
|
||||
//
|
||||
// Deprecated: use containerd [cerrdefs.IsPermissionDenied]
|
||||
var IsForbidden = cerrdefs.IsPermissionDenied
|
||||
|
||||
// IsSystem returns if the passed in error is an [ErrSystem].
|
||||
func IsSystem(err error) bool {
|
||||
_, ok := getImplementer(err).(ErrSystem)
|
||||
return ok
|
||||
}
|
||||
//
|
||||
// Deprecated: use containerd [cerrdefs.IsInternal]
|
||||
var IsSystem = cerrdefs.IsInternal
|
||||
|
||||
// IsNotModified returns if the passed in error is an [ErrNotModified].
|
||||
func IsNotModified(err error) bool {
|
||||
_, ok := getImplementer(err).(ErrNotModified)
|
||||
return ok
|
||||
}
|
||||
//
|
||||
// Deprecated: use containerd [cerrdefs.IsNotModified]
|
||||
var IsNotModified = cerrdefs.IsNotModified
|
||||
|
||||
// IsNotImplemented returns if the passed in error is an [ErrNotImplemented].
|
||||
func IsNotImplemented(err error) bool {
|
||||
_, ok := getImplementer(err).(ErrNotImplemented)
|
||||
return ok
|
||||
}
|
||||
//
|
||||
// Deprecated: use containerd [cerrdefs.IsNotImplemented]
|
||||
var IsNotImplemented = cerrdefs.IsNotImplemented
|
||||
|
||||
// IsUnknown returns if the passed in error is an [ErrUnknown].
|
||||
func IsUnknown(err error) bool {
|
||||
_, ok := getImplementer(err).(ErrUnknown)
|
||||
return ok
|
||||
}
|
||||
//
|
||||
// Deprecated: use containerd [cerrdefs.IsUnknown]
|
||||
var IsUnknown = cerrdefs.IsUnknown
|
||||
|
||||
// IsCancelled returns if the passed in error is an [ErrCancelled].
|
||||
func IsCancelled(err error) bool {
|
||||
_, ok := getImplementer(err).(ErrCancelled)
|
||||
return ok
|
||||
}
|
||||
//
|
||||
// Deprecated: use containerd [cerrdefs.IsCanceled]
|
||||
var IsCancelled = cerrdefs.IsCanceled
|
||||
|
||||
// IsDeadline returns if the passed in error is an [ErrDeadline].
|
||||
func IsDeadline(err error) bool {
|
||||
_, ok := getImplementer(err).(ErrDeadline)
|
||||
return ok
|
||||
}
|
||||
//
|
||||
// Deprecated: use containerd [cerrdefs.IsDeadlineExceeded]
|
||||
var IsDeadline = cerrdefs.IsDeadlineExceeded
|
||||
|
||||
// IsDataLoss returns if the passed in error is an [ErrDataLoss].
|
||||
func IsDataLoss(err error) bool {
|
||||
_, ok := getImplementer(err).(ErrDataLoss)
|
||||
return ok
|
||||
}
|
||||
//
|
||||
// Deprecated: use containerd [cerrdefs.IsDataLoss]
|
||||
var IsDataLoss = cerrdefs.IsDataLoss
|
||||
|
||||
// IsContext returns if the passed in error is due to context cancellation or deadline exceeded.
|
||||
func IsContext(err error) bool {
|
||||
|
||||
Reference in New Issue
Block a user