errors.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package lib
  2. import (
  3. "errors"
  4. "fmt"
  5. )
  6. var ErrConnectionFailed = errors.New("Cannot connect to the Docker daemon. Is the docker daemon running on this host?")
  7. // imageNotFoundError implements an error returned when an image is not in the docker host.
  8. type imageNotFoundError struct {
  9. imageID string
  10. }
  11. // Error returns a string representation of an imageNotFoundError
  12. func (i imageNotFoundError) Error() string {
  13. return fmt.Sprintf("Image not found: %s", i.imageID)
  14. }
  15. // IsImageNotFound returns true if the error is caused
  16. // when an image is not found in the docker host.
  17. func IsErrImageNotFound(err error) bool {
  18. _, ok := err.(imageNotFoundError)
  19. return ok
  20. }
  21. // unauthorizedError represents an authorization error in a remote registry.
  22. type unauthorizedError struct {
  23. cause error
  24. }
  25. // Error returns a string representation of an unauthorizedError
  26. func (u unauthorizedError) Error() string {
  27. return u.cause.Error()
  28. }
  29. // IsUnauthorized returns true if the error is caused
  30. // when an the remote registry authentication fails
  31. func IsErrUnauthorized(err error) bool {
  32. _, ok := err.(unauthorizedError)
  33. return ok
  34. }