errors.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package errors
  2. import "errors"
  3. // General exit codes
  4. const (
  5. CodeOk int = iota // Used when the program exits without errors
  6. CodeUnknown // Used when no other exit code is appropriate
  7. )
  8. // Taskfile related exit codes
  9. const (
  10. CodeTaskfileNotFound int = iota + 100
  11. CodeTaskfileAlreadyExists
  12. CodeTaskfileDecode
  13. CodeTaskfileFetchFailed
  14. CodeTaskfileNotTrusted
  15. CodeTaskfileNotSecure
  16. CodeTaskfileCacheNotFound
  17. CodeTaskfileVersionCheckError
  18. CodeTaskfileNetworkTimeout
  19. CodeTaskfileInvalid
  20. CodeTaskfileCycle
  21. )
  22. // Task related exit codes
  23. const (
  24. CodeTaskNotFound int = iota + 200
  25. CodeTaskRunError
  26. CodeTaskInternal
  27. CodeTaskNameConflict
  28. CodeTaskCalledTooManyTimes
  29. CodeTaskCancelled
  30. CodeTaskMissingRequiredVars
  31. CodeTaskNotAllowedVars
  32. )
  33. // TaskError extends the standard error interface with a Code method. This code will
  34. // be used as the exit code of the program which allows the user to distinguish
  35. // between different types of errors.
  36. type TaskError interface {
  37. error
  38. Code() int
  39. }
  40. // New returns an error that formats as the given text. Each call to New returns
  41. // a distinct error value even if the text is identical. This wraps the standard
  42. // errors.New function so that we don't need to alias that package.
  43. func New(text string) error {
  44. return errors.New(text)
  45. }
  46. // Is wraps the standard errors.Is function so that we don't need to alias that package.
  47. func Is(err, target error) bool {
  48. return errors.Is(err, target)
  49. }
  50. // As wraps the standard errors.As function so that we don't need to alias that package.
  51. func As(err error, target any) bool {
  52. return errors.As(err, target)
  53. }
  54. // Unwrap wraps the standard errors.Unwrap function so that we don't need to alias that package.
  55. func Unwrap(err error) error {
  56. return errors.Unwrap(err)
  57. }