error.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. package credentials
  2. // ErrCredentialsNotFound standarizes the not found error, so every helper returns
  3. // the same message and docker can handle it properly.
  4. const errCredentialsNotFoundMessage = "credentials not found in native keychain"
  5. // errCredentialsNotFound represents an error
  6. // raised when credentials are not in the store.
  7. type errCredentialsNotFound struct{}
  8. // Error returns the standard error message
  9. // for when the credentials are not in the store.
  10. func (errCredentialsNotFound) Error() string {
  11. return errCredentialsNotFoundMessage
  12. }
  13. // NewErrCredentialsNotFound creates a new error
  14. // for when the credentials are not in the store.
  15. func NewErrCredentialsNotFound() error {
  16. return errCredentialsNotFound{}
  17. }
  18. // IsErrCredentialsNotFound returns true if the error
  19. // was caused by not having a set of credentials in a store.
  20. func IsErrCredentialsNotFound(err error) bool {
  21. _, ok := err.(errCredentialsNotFound)
  22. return ok
  23. }
  24. // IsErrCredentialsNotFoundMessage returns true if the error
  25. // was caused by not having a set of credentials in a store.
  26. //
  27. // This function helps to check messages returned by an
  28. // external program via its standard output.
  29. func IsErrCredentialsNotFoundMessage(err string) bool {
  30. return err == errCredentialsNotFoundMessage
  31. }