errors.go 2.8 KB

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