1package errdefs // import "github.com/docker/docker/errdefs" 2 3type causer interface { 4 Cause() error 5} 6 7func getImplementer(err error) error { 8 switch e := err.(type) { 9 case 10 ErrNotFound, 11 ErrInvalidParameter, 12 ErrConflict, 13 ErrUnauthorized, 14 ErrUnavailable, 15 ErrForbidden, 16 ErrSystem, 17 ErrNotModified, 18 ErrNotImplemented, 19 ErrCancelled, 20 ErrDeadline, 21 ErrDataLoss, 22 ErrUnknown: 23 return err 24 case causer: 25 return getImplementer(e.Cause()) 26 default: 27 return err 28 } 29} 30 31// IsNotFound returns if the passed in error is an ErrNotFound 32func IsNotFound(err error) bool { 33 _, ok := getImplementer(err).(ErrNotFound) 34 return ok 35} 36 37// IsInvalidParameter returns if the passed in error is an ErrInvalidParameter 38func IsInvalidParameter(err error) bool { 39 _, ok := getImplementer(err).(ErrInvalidParameter) 40 return ok 41} 42 43// IsConflict returns if the passed in error is an ErrConflict 44func IsConflict(err error) bool { 45 _, ok := getImplementer(err).(ErrConflict) 46 return ok 47} 48 49// IsUnauthorized returns if the passed in error is an ErrUnauthorized 50func IsUnauthorized(err error) bool { 51 _, ok := getImplementer(err).(ErrUnauthorized) 52 return ok 53} 54 55// IsUnavailable returns if the passed in error is an ErrUnavailable 56func IsUnavailable(err error) bool { 57 _, ok := getImplementer(err).(ErrUnavailable) 58 return ok 59} 60 61// IsForbidden returns if the passed in error is an ErrForbidden 62func IsForbidden(err error) bool { 63 _, ok := getImplementer(err).(ErrForbidden) 64 return ok 65} 66 67// IsSystem returns if the passed in error is an ErrSystem 68func IsSystem(err error) bool { 69 _, ok := getImplementer(err).(ErrSystem) 70 return ok 71} 72 73// IsNotModified returns if the passed in error is a NotModified error 74func IsNotModified(err error) bool { 75 _, ok := getImplementer(err).(ErrNotModified) 76 return ok 77} 78 79// IsNotImplemented returns if the passed in error is an ErrNotImplemented 80func IsNotImplemented(err error) bool { 81 _, ok := getImplementer(err).(ErrNotImplemented) 82 return ok 83} 84 85// IsUnknown returns if the passed in error is an ErrUnknown 86func IsUnknown(err error) bool { 87 _, ok := getImplementer(err).(ErrUnknown) 88 return ok 89} 90 91// IsCancelled returns if the passed in error is an ErrCancelled 92func IsCancelled(err error) bool { 93 _, ok := getImplementer(err).(ErrCancelled) 94 return ok 95} 96 97// IsDeadline returns if the passed in error is an ErrDeadline 98func IsDeadline(err error) bool { 99 _, ok := getImplementer(err).(ErrDeadline) 100 return ok 101} 102 103// IsDataLoss returns if the passed in error is an ErrDataLoss 104func IsDataLoss(err error) bool { 105 _, ok := getImplementer(err).(ErrDataLoss) 106 return ok 107} 108