errors.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. // unauthorizedError represents an authorization error in a remote registry.
  23. type unauthorizedError struct {
  24. cause error
  25. }
  26. // Error returns a string representation of an unauthorizedError
  27. func (u unauthorizedError) Error() string {
  28. return u.cause.Error()
  29. }
  30. // IsErrUnauthorized returns true if the error is caused
  31. // when an the remote registry authentication fails
  32. func IsErrUnauthorized(err error) bool {
  33. _, ok := err.(unauthorizedError)
  34. return ok
  35. }