123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- package client
- import (
- "errors"
- "fmt"
- )
- // ErrConnectionFailed is an error raised when the connection between the client and the server failed.
- var ErrConnectionFailed = errors.New("Cannot connect to the Docker daemon. Is the docker daemon running on this host?")
- // ErrorConnectionFailed returns an error with host in the error message when connection to docker daemon failed.
- func ErrorConnectionFailed(host string) error {
- return fmt.Errorf("Cannot connect to the Docker daemon at %s. Is the docker daemon running?", host)
- }
- type notFound interface {
- error
- NotFound() bool // Is the error a NotFound error
- }
- // IsErrNotFound returns true if the error is caused with an
- // object (image, container, network, volume, …) is not found in the docker host.
- func IsErrNotFound(err error) bool {
- te, ok := err.(notFound)
- return ok && te.NotFound()
- }
- // imageNotFoundError implements an error returned when an image is not in the docker host.
- type imageNotFoundError struct {
- imageID string
- }
- // NotFound indicates that this error type is of NotFound
- func (e imageNotFoundError) NotFound() bool {
- return true
- }
- // Error returns a string representation of an imageNotFoundError
- func (e imageNotFoundError) Error() string {
- return fmt.Sprintf("Error: No such image: %s", e.imageID)
- }
- // IsErrImageNotFound returns true if the error is caused
- // when an image is not found in the docker host.
- func IsErrImageNotFound(err error) bool {
- return IsErrNotFound(err)
- }
- // containerNotFoundError implements an error returned when a container is not in the docker host.
- type containerNotFoundError struct {
- containerID string
- }
- // NotFound indicates that this error type is of NotFound
- func (e containerNotFoundError) NotFound() bool {
- return true
- }
- // Error returns a string representation of a containerNotFoundError
- func (e containerNotFoundError) Error() string {
- return fmt.Sprintf("Error: No such container: %s", e.containerID)
- }
- // IsErrContainerNotFound returns true if the error is caused
- // when a container is not found in the docker host.
- func IsErrContainerNotFound(err error) bool {
- return IsErrNotFound(err)
- }
- // networkNotFoundError implements an error returned when a network is not in the docker host.
- type networkNotFoundError struct {
- networkID string
- }
- // NotFound indicates that this error type is of NotFound
- func (e networkNotFoundError) NotFound() bool {
- return true
- }
- // Error returns a string representation of a networkNotFoundError
- func (e networkNotFoundError) Error() string {
- return fmt.Sprintf("Error: No such network: %s", e.networkID)
- }
- // IsErrNetworkNotFound returns true if the error is caused
- // when a network is not found in the docker host.
- func IsErrNetworkNotFound(err error) bool {
- return IsErrNotFound(err)
- }
- // volumeNotFoundError implements an error returned when a volume is not in the docker host.
- type volumeNotFoundError struct {
- volumeID string
- }
- // NotFound indicates that this error type is of NotFound
- func (e volumeNotFoundError) NotFound() bool {
- return true
- }
- // Error returns a string representation of a volumeNotFoundError
- func (e volumeNotFoundError) Error() string {
- return fmt.Sprintf("Error: No such volume: %s", e.volumeID)
- }
- // IsErrVolumeNotFound returns true if the error is caused
- // when a volume is not found in the docker host.
- func IsErrVolumeNotFound(err error) bool {
- return IsErrNotFound(err)
- }
- // unauthorizedError represents an authorization error in a remote registry.
- type unauthorizedError struct {
- cause error
- }
- // Error returns a string representation of an unauthorizedError
- func (u unauthorizedError) Error() string {
- return u.cause.Error()
- }
- // IsErrUnauthorized returns true if the error is caused
- // when a remote registry authentication fails
- func IsErrUnauthorized(err error) bool {
- _, ok := err.(unauthorizedError)
- return ok
- }
- // nodeNotFoundError implements an error returned when a node is not found.
- type nodeNotFoundError struct {
- nodeID string
- }
- // Error returns a string representation of a nodeNotFoundError
- func (e nodeNotFoundError) Error() string {
- return fmt.Sprintf("Error: No such node: %s", e.nodeID)
- }
- // NotFound indicates that this error type is of NotFound
- func (e nodeNotFoundError) NotFound() bool {
- return true
- }
- // IsErrNodeNotFound returns true if the error is caused
- // when a node is not found.
- func IsErrNodeNotFound(err error) bool {
- _, ok := err.(nodeNotFoundError)
- return ok
- }
- // serviceNotFoundError implements an error returned when a service is not found.
- type serviceNotFoundError struct {
- serviceID string
- }
- // Error returns a string representation of a serviceNotFoundError
- func (e serviceNotFoundError) Error() string {
- return fmt.Sprintf("Error: No such service: %s", e.serviceID)
- }
- // NotFound indicates that this error type is of NotFound
- func (e serviceNotFoundError) NotFound() bool {
- return true
- }
- // IsErrServiceNotFound returns true if the error is caused
- // when a service is not found.
- func IsErrServiceNotFound(err error) bool {
- _, ok := err.(serviceNotFoundError)
- return ok
- }
- // taskNotFoundError implements an error returned when a task is not found.
- type taskNotFoundError struct {
- taskID string
- }
- // Error returns a string representation of a taskNotFoundError
- func (e taskNotFoundError) Error() string {
- return fmt.Sprintf("Error: No such task: %s", e.taskID)
- }
- // NotFound indicates that this error type is of NotFound
- func (e taskNotFoundError) NotFound() bool {
- return true
- }
- // IsErrTaskNotFound returns true if the error is caused
- // when a task is not found.
- func IsErrTaskNotFound(err error) bool {
- _, ok := err.(taskNotFoundError)
- return ok
- }
- type pluginPermissionDenied struct {
- name string
- }
- func (e pluginPermissionDenied) Error() string {
- return "Permission denied while installing plugin " + e.name
- }
- // IsErrPluginPermissionDenied returns true if the error is caused
- // when a user denies a plugin's permissions
- func IsErrPluginPermissionDenied(err error) bool {
- _, ok := err.(pluginPermissionDenied)
- return ok
- }
|