errors.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. Copyright 2020 Docker, Inc.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package errdefs
  14. import (
  15. "github.com/pkg/errors"
  16. )
  17. var (
  18. // ErrNotFound is returned when an object is not found
  19. ErrNotFound = errors.New("not found")
  20. // ErrAlreadyExists is returned when an object already exists
  21. ErrAlreadyExists = errors.New("already exists")
  22. // ErrForbidden is returned when an operation is not permitted
  23. ErrForbidden = errors.New("forbidden")
  24. // ErrUnknown is returned when the error type is unmapped
  25. ErrUnknown = errors.New("unknown")
  26. // ErrLoginFailed is returned when login failed
  27. ErrLoginFailed = errors.New("login failed")
  28. // ErrNotImplemented is returned when a backend doesn't implement
  29. // an action
  30. ErrNotImplemented = errors.New("not implemented")
  31. // ErrParsingFailed is returned when a string cannot be parsed
  32. ErrParsingFailed = errors.New("parsing failed")
  33. // ErrWrongContextType is returned when the caller tries to get a context
  34. // with the wrong type
  35. ErrWrongContextType = errors.New("wrong context type")
  36. )
  37. // IsNotFoundError returns true if the unwrapped error is ErrNotFound
  38. func IsNotFoundError(err error) bool {
  39. return errors.Is(err, ErrNotFound)
  40. }
  41. // IsAlreadyExistsError returns true if the unwrapped error is ErrAlreadyExists
  42. func IsAlreadyExistsError(err error) bool {
  43. return errors.Is(err, ErrAlreadyExists)
  44. }
  45. // IsForbiddenError returns true if the unwrapped error is ErrForbidden
  46. func IsForbiddenError(err error) bool {
  47. return errors.Is(err, ErrForbidden)
  48. }
  49. // IsUnknownError returns true if the unwrapped error is ErrUnknown
  50. func IsUnknownError(err error) bool {
  51. return errors.Is(err, ErrUnknown)
  52. }
  53. // IsErrNotImplemented returns true if the unwrapped error is ErrNotImplemented
  54. func IsErrNotImplemented(err error) bool {
  55. return errors.Is(err, ErrNotImplemented)
  56. }
  57. // IsErrParsingFailed returns true if the unwrapped error is ErrParsingFailed
  58. func IsErrParsingFailed(err error) bool {
  59. return errors.Is(err, ErrParsingFailed)
  60. }