errors.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. Copyright 2020 Docker Compose CLI authors
  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. const (
  18. //ExitCodeLoginRequired exit code when command cannot execute because it requires cloud login
  19. // This will be used by VSCode to detect when creating context if the user needs to login first
  20. ExitCodeLoginRequired = 5
  21. )
  22. var (
  23. // ErrNotFound is returned when an object is not found
  24. ErrNotFound = errors.New("not found")
  25. // ErrAlreadyExists is returned when an object already exists
  26. ErrAlreadyExists = errors.New("already exists")
  27. // ErrForbidden is returned when an operation is not permitted
  28. ErrForbidden = errors.New("forbidden")
  29. // ErrUnknown is returned when the error type is unmapped
  30. ErrUnknown = errors.New("unknown")
  31. // ErrLoginFailed is returned when login failed
  32. ErrLoginFailed = errors.New("login failed")
  33. // ErrLoginRequired is returned when login is required for a specific action
  34. ErrLoginRequired = errors.New("login required")
  35. // ErrNotImplemented is returned when a backend doesn't implement
  36. // an action
  37. ErrNotImplemented = errors.New("not implemented")
  38. // ErrCanceled is returned when the command was canceled by user
  39. ErrCanceled = errors.New("canceled")
  40. // ErrParsingFailed is returned when a string cannot be parsed
  41. ErrParsingFailed = errors.New("parsing failed")
  42. // ErrWrongContextType is returned when the caller tries to get a context
  43. // with the wrong type
  44. ErrWrongContextType = errors.New("wrong context type")
  45. )
  46. // IsNotFoundError returns true if the unwrapped error is ErrNotFound
  47. func IsNotFoundError(err error) bool {
  48. return errors.Is(err, ErrNotFound)
  49. }
  50. // IsAlreadyExistsError returns true if the unwrapped error is ErrAlreadyExists
  51. func IsAlreadyExistsError(err error) bool {
  52. return errors.Is(err, ErrAlreadyExists)
  53. }
  54. // IsForbiddenError returns true if the unwrapped error is ErrForbidden
  55. func IsForbiddenError(err error) bool {
  56. return errors.Is(err, ErrForbidden)
  57. }
  58. // IsUnknownError returns true if the unwrapped error is ErrUnknown
  59. func IsUnknownError(err error) bool {
  60. return errors.Is(err, ErrUnknown)
  61. }
  62. // IsErrNotImplemented returns true if the unwrapped error is ErrNotImplemented
  63. func IsErrNotImplemented(err error) bool {
  64. return errors.Is(err, ErrNotImplemented)
  65. }
  66. // IsErrParsingFailed returns true if the unwrapped error is ErrParsingFailed
  67. func IsErrParsingFailed(err error) bool {
  68. return errors.Is(err, ErrParsingFailed)
  69. }
  70. // IsErrCanceled returns true if the unwrapped error is ErrCanceled
  71. func IsErrCanceled(err error) bool {
  72. return errors.Is(err, ErrCanceled)
  73. }