errors.go 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. Copyright (c) 2020 Docker Inc.
  3. Permission is hereby granted, free of charge, to any person
  4. obtaining a copy of this software and associated documentation
  5. files (the "Software"), to deal in the Software without
  6. restriction, including without limitation the rights to use, copy,
  7. modify, merge, publish, distribute, sublicense, and/or sell copies
  8. of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be
  11. included in all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  13. EXPRESS OR IMPLIED,
  14. INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  16. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  17. HOLDERS BE LIABLE FOR ANY CLAIM,
  18. DAMAGES OR OTHER LIABILITY,
  19. WHETHER IN AN ACTION OF CONTRACT,
  20. TORT OR OTHERWISE,
  21. ARISING FROM, OUT OF OR IN CONNECTION WITH
  22. THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. */
  24. package errdefs
  25. import (
  26. "github.com/pkg/errors"
  27. )
  28. var (
  29. // ErrNotFound is returned when an object is not found
  30. ErrNotFound = errors.New("not found")
  31. // ErrAlreadyExists is returned when an object already exists
  32. ErrAlreadyExists = errors.New("already exists")
  33. // ErrForbidden is returned when an operation is not permitted
  34. ErrForbidden = errors.New("forbidden")
  35. // ErrUnknown is returned when the error type is unmapped
  36. ErrUnknown = errors.New("unknown")
  37. // ErrLoginFailed is returned when login failed
  38. ErrLoginFailed = errors.New("login failed")
  39. // ErrNotImplemented is returned when a backend doesn't implement
  40. // an action
  41. ErrNotImplemented = errors.New("not implemented")
  42. // ErrParsingFailed is returned when a string cannot be parsed
  43. ErrParsingFailed = errors.New("parsing failed")
  44. )
  45. // IsNotFoundError returns true if the unwrapped error is ErrNotFound
  46. func IsNotFoundError(err error) bool {
  47. return errors.Is(err, ErrNotFound)
  48. }
  49. // IsAlreadyExistsError returns true if the unwrapped error is ErrAlreadyExists
  50. func IsAlreadyExistsError(err error) bool {
  51. return errors.Is(err, ErrAlreadyExists)
  52. }
  53. // IsForbiddenError returns true if the unwrapped error is ErrForbidden
  54. func IsForbiddenError(err error) bool {
  55. return errors.Is(err, ErrForbidden)
  56. }
  57. // IsUnknownError returns true if the unwrapped error is ErrUnknown
  58. func IsUnknownError(err error) bool {
  59. return errors.Is(err, ErrUnknown)
  60. }
  61. // IsErrNotImplemented returns true if the unwrapped error is ErrNotImplemented
  62. func IsErrNotImplemented(err error) bool {
  63. return errors.Is(err, ErrNotImplemented)
  64. }
  65. // IsErrParsingFailed returns true if the unwrapped error is ErrParsingFailed
  66. func IsErrParsingFailed(err error) bool {
  67. return errors.Is(err, ErrParsingFailed)
  68. }