github.com/endophage/docker@v1.4.2-0.20161027011718-242853499895/client/errors.go (about) 1 package client 2 3 import ( 4 "errors" 5 "fmt" 6 ) 7 8 // ErrConnectionFailed is an 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 // ErrorConnectionFailed returns an error with host in the error message when connection to docker daemon failed. 12 func ErrorConnectionFailed(host string) error { 13 return fmt.Errorf("Cannot connect to the Docker daemon at %s. Is the docker daemon running?", host) 14 } 15 16 type notFound interface { 17 error 18 NotFound() bool // Is the error a NotFound error 19 } 20 21 // IsErrNotFound returns true if the error is caused with an 22 // object (image, container, network, volume, …) is not found in the docker host. 23 func IsErrNotFound(err error) bool { 24 te, ok := err.(notFound) 25 return ok && te.NotFound() 26 } 27 28 // imageNotFoundError implements an error returned when an image is not in the docker host. 29 type imageNotFoundError struct { 30 imageID string 31 } 32 33 // NotFound indicates that this error type is of NotFound 34 func (e imageNotFoundError) NotFound() bool { 35 return true 36 } 37 38 // Error returns a string representation of an imageNotFoundError 39 func (e imageNotFoundError) Error() string { 40 return fmt.Sprintf("Error: No such image: %s", e.imageID) 41 } 42 43 // IsErrImageNotFound returns true if the error is caused 44 // when an image is not found in the docker host. 45 func IsErrImageNotFound(err error) bool { 46 return IsErrNotFound(err) 47 } 48 49 // containerNotFoundError implements an error returned when a container is not in the docker host. 50 type containerNotFoundError struct { 51 containerID string 52 } 53 54 // NotFound indicates that this error type is of NotFound 55 func (e containerNotFoundError) NotFound() bool { 56 return true 57 } 58 59 // Error returns a string representation of a containerNotFoundError 60 func (e containerNotFoundError) Error() string { 61 return fmt.Sprintf("Error: No such container: %s", e.containerID) 62 } 63 64 // IsErrContainerNotFound returns true if the error is caused 65 // when a container is not found in the docker host. 66 func IsErrContainerNotFound(err error) bool { 67 return IsErrNotFound(err) 68 } 69 70 // networkNotFoundError implements an error returned when a network is not in the docker host. 71 type networkNotFoundError struct { 72 networkID string 73 } 74 75 // NotFound indicates that this error type is of NotFound 76 func (e networkNotFoundError) NotFound() bool { 77 return true 78 } 79 80 // Error returns a string representation of a networkNotFoundError 81 func (e networkNotFoundError) Error() string { 82 return fmt.Sprintf("Error: No such network: %s", e.networkID) 83 } 84 85 // IsErrNetworkNotFound returns true if the error is caused 86 // when a network is not found in the docker host. 87 func IsErrNetworkNotFound(err error) bool { 88 return IsErrNotFound(err) 89 } 90 91 // volumeNotFoundError implements an error returned when a volume is not in the docker host. 92 type volumeNotFoundError struct { 93 volumeID string 94 } 95 96 // NotFound indicates that this error type is of NotFound 97 func (e volumeNotFoundError) NotFound() bool { 98 return true 99 } 100 101 // Error returns a string representation of a volumeNotFoundError 102 func (e volumeNotFoundError) Error() string { 103 return fmt.Sprintf("Error: No such volume: %s", e.volumeID) 104 } 105 106 // IsErrVolumeNotFound returns true if the error is caused 107 // when a volume is not found in the docker host. 108 func IsErrVolumeNotFound(err error) bool { 109 return IsErrNotFound(err) 110 } 111 112 // unauthorizedError represents an authorization error in a remote registry. 113 type unauthorizedError struct { 114 cause error 115 } 116 117 // Error returns a string representation of an unauthorizedError 118 func (u unauthorizedError) Error() string { 119 return u.cause.Error() 120 } 121 122 // IsErrUnauthorized returns true if the error is caused 123 // when a remote registry authentication fails 124 func IsErrUnauthorized(err error) bool { 125 _, ok := err.(unauthorizedError) 126 return ok 127 } 128 129 // nodeNotFoundError implements an error returned when a node is not found. 130 type nodeNotFoundError struct { 131 nodeID string 132 } 133 134 // Error returns a string representation of a nodeNotFoundError 135 func (e nodeNotFoundError) Error() string { 136 return fmt.Sprintf("Error: No such node: %s", e.nodeID) 137 } 138 139 // NotFound indicates that this error type is of NotFound 140 func (e nodeNotFoundError) NotFound() bool { 141 return true 142 } 143 144 // IsErrNodeNotFound returns true if the error is caused 145 // when a node is not found. 146 func IsErrNodeNotFound(err error) bool { 147 _, ok := err.(nodeNotFoundError) 148 return ok 149 } 150 151 // serviceNotFoundError implements an error returned when a service is not found. 152 type serviceNotFoundError struct { 153 serviceID string 154 } 155 156 // Error returns a string representation of a serviceNotFoundError 157 func (e serviceNotFoundError) Error() string { 158 return fmt.Sprintf("Error: No such service: %s", e.serviceID) 159 } 160 161 // NotFound indicates that this error type is of NotFound 162 func (e serviceNotFoundError) NotFound() bool { 163 return true 164 } 165 166 // IsErrServiceNotFound returns true if the error is caused 167 // when a service is not found. 168 func IsErrServiceNotFound(err error) bool { 169 _, ok := err.(serviceNotFoundError) 170 return ok 171 } 172 173 // taskNotFoundError implements an error returned when a task is not found. 174 type taskNotFoundError struct { 175 taskID string 176 } 177 178 // Error returns a string representation of a taskNotFoundError 179 func (e taskNotFoundError) Error() string { 180 return fmt.Sprintf("Error: No such task: %s", e.taskID) 181 } 182 183 // NotFound indicates that this error type is of NotFound 184 func (e taskNotFoundError) NotFound() bool { 185 return true 186 } 187 188 // IsErrTaskNotFound returns true if the error is caused 189 // when a task is not found. 190 func IsErrTaskNotFound(err error) bool { 191 _, ok := err.(taskNotFoundError) 192 return ok 193 } 194 195 type pluginPermissionDenied struct { 196 name string 197 } 198 199 func (e pluginPermissionDenied) Error() string { 200 return "Permission denied while installing plugin " + e.name 201 } 202 203 // IsErrPluginPermissionDenied returns true if the error is caused 204 // when a user denies a plugin's permissions 205 func IsErrPluginPermissionDenied(err error) bool { 206 _, ok := err.(pluginPermissionDenied) 207 return ok 208 }