6 "github.com/docker/docker/api/types/versions"
7 "github.com/pkg/errors"
10 // errConnectionFailed implements an error returned when connection failed.
11 type errConnectionFailed struct {
15 // Error returns a string representation of an errConnectionFailed
16 func (err errConnectionFailed) Error() string {
18 return "Cannot connect to the docker daemon. Is the docker daemon running on this host?"
20 return fmt.Sprintf("Cannot connect to the docker daemon at %s. Is the docker daemon running?", err.host)
23 // IsErrConnectionFailed returns true if the error is caused by connection failed.
24 func IsErrConnectionFailed(err error) bool {
25 _, ok := errors.Cause(err).(errConnectionFailed)
29 // ErrorConnectionFailed returns an error with host in the error message when connection to docker daemon failed.
30 func ErrorConnectionFailed(host string) error {
31 return errConnectionFailed{host: host}
34 type notFound interface {
36 NotFound() bool // Is the error a NotFound error
39 // IsErrNotFound returns true if the error is caused with an
40 // object (image, container, network, volume, …) is not found in the docker host.
41 func IsErrNotFound(err error) bool {
42 te, ok := err.(notFound)
43 return ok && te.NotFound()
46 // imageNotFoundError implements an error returned when an image is not in the docker host.
47 type imageNotFoundError struct {
51 // NotFound indicates that this error type is of NotFound
52 func (e imageNotFoundError) NotFound() bool {
56 // Error returns a string representation of an imageNotFoundError
57 func (e imageNotFoundError) Error() string {
58 return fmt.Sprintf("Error: No such image: %s", e.imageID)
61 // IsErrImageNotFound returns true if the error is caused
62 // when an image is not found in the docker host.
63 func IsErrImageNotFound(err error) bool {
64 return IsErrNotFound(err)
67 // containerNotFoundError implements an error returned when a container is not in the docker host.
68 type containerNotFoundError struct {
72 // NotFound indicates that this error type is of NotFound
73 func (e containerNotFoundError) NotFound() bool {
77 // Error returns a string representation of a containerNotFoundError
78 func (e containerNotFoundError) Error() string {
79 return fmt.Sprintf("Error: No such container: %s", e.containerID)
82 // IsErrContainerNotFound returns true if the error is caused
83 // when a container is not found in the docker host.
84 func IsErrContainerNotFound(err error) bool {
85 return IsErrNotFound(err)
88 // networkNotFoundError implements an error returned when a network is not in the docker host.
89 type networkNotFoundError struct {
93 // NotFound indicates that this error type is of NotFound
94 func (e networkNotFoundError) NotFound() bool {
98 // Error returns a string representation of a networkNotFoundError
99 func (e networkNotFoundError) Error() string {
100 return fmt.Sprintf("Error: No such network: %s", e.networkID)
103 // IsErrNetworkNotFound returns true if the error is caused
104 // when a network is not found in the docker host.
105 func IsErrNetworkNotFound(err error) bool {
106 return IsErrNotFound(err)
109 // volumeNotFoundError implements an error returned when a volume is not in the docker host.
110 type volumeNotFoundError struct {
114 // NotFound indicates that this error type is of NotFound
115 func (e volumeNotFoundError) NotFound() bool {
119 // Error returns a string representation of a volumeNotFoundError
120 func (e volumeNotFoundError) Error() string {
121 return fmt.Sprintf("Error: No such volume: %s", e.volumeID)
124 // IsErrVolumeNotFound returns true if the error is caused
125 // when a volume is not found in the docker host.
126 func IsErrVolumeNotFound(err error) bool {
127 return IsErrNotFound(err)
130 // unauthorizedError represents an authorization error in a remote registry.
131 type unauthorizedError struct {
135 // Error returns a string representation of an unauthorizedError
136 func (u unauthorizedError) Error() string {
137 return u.cause.Error()
140 // IsErrUnauthorized returns true if the error is caused
141 // when a remote registry authentication fails
142 func IsErrUnauthorized(err error) bool {
143 _, ok := err.(unauthorizedError)
147 // nodeNotFoundError implements an error returned when a node is not found.
148 type nodeNotFoundError struct {
152 // Error returns a string representation of a nodeNotFoundError
153 func (e nodeNotFoundError) Error() string {
154 return fmt.Sprintf("Error: No such node: %s", e.nodeID)
157 // NotFound indicates that this error type is of NotFound
158 func (e nodeNotFoundError) NotFound() bool {
162 // IsErrNodeNotFound returns true if the error is caused
163 // when a node is not found.
164 func IsErrNodeNotFound(err error) bool {
165 _, ok := err.(nodeNotFoundError)
169 // serviceNotFoundError implements an error returned when a service is not found.
170 type serviceNotFoundError struct {
174 // Error returns a string representation of a serviceNotFoundError
175 func (e serviceNotFoundError) Error() string {
176 return fmt.Sprintf("Error: No such service: %s", e.serviceID)
179 // NotFound indicates that this error type is of NotFound
180 func (e serviceNotFoundError) NotFound() bool {
184 // IsErrServiceNotFound returns true if the error is caused
185 // when a service is not found.
186 func IsErrServiceNotFound(err error) bool {
187 _, ok := err.(serviceNotFoundError)
191 // taskNotFoundError implements an error returned when a task is not found.
192 type taskNotFoundError struct {
196 // Error returns a string representation of a taskNotFoundError
197 func (e taskNotFoundError) Error() string {
198 return fmt.Sprintf("Error: No such task: %s", e.taskID)
201 // NotFound indicates that this error type is of NotFound
202 func (e taskNotFoundError) NotFound() bool {
206 // IsErrTaskNotFound returns true if the error is caused
207 // when a task is not found.
208 func IsErrTaskNotFound(err error) bool {
209 _, ok := err.(taskNotFoundError)
213 type pluginPermissionDenied struct {
217 func (e pluginPermissionDenied) Error() string {
218 return "Permission denied while installing plugin " + e.name
221 // IsErrPluginPermissionDenied returns true if the error is caused
222 // when a user denies a plugin's permissions
223 func IsErrPluginPermissionDenied(err error) bool {
224 _, ok := err.(pluginPermissionDenied)
228 // NewVersionError returns an error if the APIVersion required
229 // if less than the current supported version
230 func (cli *Client) NewVersionError(APIrequired, feature string) error {
231 if versions.LessThan(cli.version, APIrequired) {
232 return fmt.Errorf("%q requires API version %s, but the Docker daemon API version is %s", feature, APIrequired, cli.version)
237 // secretNotFoundError implements an error returned when a secret is not found.
238 type secretNotFoundError struct {
242 // Error returns a string representation of a secretNotFoundError
243 func (e secretNotFoundError) Error() string {
244 return fmt.Sprintf("Error: no such secret: %s", e.name)
247 // NotFound indicates that this error type is of NotFound
248 func (e secretNotFoundError) NotFound() bool {
252 // IsErrSecretNotFound returns true if the error is caused
253 // when a secret is not found.
254 func IsErrSecretNotFound(err error) bool {
255 _, ok := err.(secretNotFoundError)
259 // configNotFoundError implements an error returned when a config is not found.
260 type configNotFoundError struct {
264 // Error returns a string representation of a configNotFoundError
265 func (e configNotFoundError) Error() string {
266 return fmt.Sprintf("Error: no such config: %s", e.name)
269 // NotFound indicates that this error type is of NotFound
270 func (e configNotFoundError) NotFound() bool {
274 // IsErrConfigNotFound returns true if the error is caused
275 // when a config is not found.
276 func IsErrConfigNotFound(err error) bool {
277 _, ok := err.(configNotFoundError)
281 // pluginNotFoundError implements an error returned when a plugin is not in the docker host.
282 type pluginNotFoundError struct {
286 // NotFound indicates that this error type is of NotFound
287 func (e pluginNotFoundError) NotFound() bool {
291 // Error returns a string representation of a pluginNotFoundError
292 func (e pluginNotFoundError) Error() string {
293 return fmt.Sprintf("Error: No such plugin: %s", e.name)
296 // IsErrPluginNotFound returns true if the error is caused
297 // when a plugin is not found in the docker host.
298 func IsErrPluginNotFound(err error) bool {
299 return IsErrNotFound(err)