errors.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package lib
  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("Image not found: %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("Container not found: %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. // unauthorizedError represents an authorization error in a remote registry.
  37. type unauthorizedError struct {
  38. cause error
  39. }
  40. // Error returns a string representation of an unauthorizedError
  41. func (u unauthorizedError) Error() string {
  42. return u.cause.Error()
  43. }
  44. // IsErrUnauthorized returns true if the error is caused
  45. // when an the remote registry authentication fails
  46. func IsErrUnauthorized(err error) bool {
  47. _, ok := err.(unauthorizedError)
  48. return ok
  49. }