errors.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. )
  32. // TaskError extends the standard error interface with a Code method. This code will
  33. // be used as the exit code of the program which allows the user to distinguish
  34. // between different types of errors.
  35. type TaskError interface {
  36. error
  37. Code() int
  38. }
  39. // New returns an error that formats as the given text. Each call to New returns
  40. // a distinct error value even if the text is identical. This wraps the standard
  41. // errors.New function so that we don't need to alias that package.
  42. func New(text string) error {
  43. return errors.New(text)
  44. }
  45. // Is wraps the standard errors.Is function so that we don't need to alias that package.
  46. func Is(err, target error) bool {
  47. return errors.Is(err, target)
  48. }
  49. // As wraps the standard errors.As function so that we don't need to alias that package.
  50. func As(err error, target any) bool {
  51. return errors.As(err, target)
  52. }
  53. // Unwrap wraps the standard errors.Unwrap function so that we don't need to alias that package.
  54. func Unwrap(err error) error {
  55. return errors.Unwrap(err)
  56. }