errors.go 990 B

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