github.com/walkingsparrow/docker@v1.4.2-0.20151218153551-b708a2249bfa/api/client/lib/errors.go (about) 1 package lib 2 3 import ( 4 "errors" 5 "fmt" 6 ) 7 8 // ErrConnectionFailed is a error raised when the connection between the client and the server failed. 9 var ErrConnectionFailed = errors.New("Cannot connect to the Docker daemon. Is the docker daemon running on this host?") 10 11 // imageNotFoundError implements an error returned when an image is not in the docker host. 12 type imageNotFoundError struct { 13 imageID string 14 } 15 16 // Error returns a string representation of an imageNotFoundError 17 func (i imageNotFoundError) Error() string { 18 return fmt.Sprintf("Error: No such image: %s", i.imageID) 19 } 20 21 // IsErrImageNotFound returns true if the error is caused 22 // when an image is not found in the docker host. 23 func IsErrImageNotFound(err error) bool { 24 _, ok := err.(imageNotFoundError) 25 return ok 26 } 27 28 // containerNotFoundError implements an error returned when a container is not in the docker host. 29 type containerNotFoundError struct { 30 containerID string 31 } 32 33 // Error returns a string representation of an containerNotFoundError 34 func (e containerNotFoundError) Error() string { 35 return fmt.Sprintf("Error: No such container: %s", e.containerID) 36 } 37 38 // IsErrContainerNotFound returns true if the error is caused 39 // when a container is not found in the docker host. 40 func IsErrContainerNotFound(err error) bool { 41 _, ok := err.(containerNotFoundError) 42 return ok 43 } 44 45 // networkNotFoundError implements an error returned when a network is not in the docker host. 46 type networkNotFoundError struct { 47 networkID string 48 } 49 50 // Error returns a string representation of an networkNotFoundError 51 func (e networkNotFoundError) Error() string { 52 return fmt.Sprintf("Error: No such network: %s", e.networkID) 53 } 54 55 // IsErrNetworkNotFound returns true if the error is caused 56 // when a network is not found in the docker host. 57 func IsErrNetworkNotFound(err error) bool { 58 _, ok := err.(networkNotFoundError) 59 return ok 60 } 61 62 // volumeNotFoundError implements an error returned when a volume is not in the docker host. 63 type volumeNotFoundError struct { 64 volumeID string 65 } 66 67 // Error returns a string representation of an networkNotFoundError 68 func (e volumeNotFoundError) Error() string { 69 return fmt.Sprintf("Error: No such volume: %s", e.volumeID) 70 } 71 72 // IsErrVolumeNotFound returns true if the error is caused 73 // when a volume is not found in the docker host. 74 func IsErrVolumeNotFound(err error) bool { 75 _, ok := err.(networkNotFoundError) 76 return ok 77 } 78 79 // unauthorizedError represents an authorization error in a remote registry. 80 type unauthorizedError struct { 81 cause error 82 } 83 84 // Error returns a string representation of an unauthorizedError 85 func (u unauthorizedError) Error() string { 86 return u.cause.Error() 87 } 88 89 // IsErrUnauthorized returns true if the error is caused 90 // when an the remote registry authentication fails 91 func IsErrUnauthorized(err error) bool { 92 _, ok := err.(unauthorizedError) 93 return ok 94 }