errors.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package exec
  2. import "github.com/pkg/errors"
  3. var (
  4. // ErrRuntimeUnsupported encountered when a task requires a runtime
  5. // unsupported by the executor.
  6. ErrRuntimeUnsupported = errors.New("exec: unsupported runtime")
  7. // ErrTaskPrepared is called if the task is already prepared.
  8. ErrTaskPrepared = errors.New("exec: task already prepared")
  9. // ErrTaskStarted can be returned from any operation that cannot be
  10. // performed because the task has already been started. This does not imply
  11. // that the task is running but rather that it is no longer valid to call
  12. // Start.
  13. ErrTaskStarted = errors.New("exec: task already started")
  14. // ErrTaskUpdateRejected is returned if a task update is rejected by a controller.
  15. ErrTaskUpdateRejected = errors.New("exec: task update rejected")
  16. // ErrControllerClosed returned when a task controller has been closed.
  17. ErrControllerClosed = errors.New("exec: controller closed")
  18. // ErrTaskRetry is returned by Do when an operation failed by should be
  19. // retried. The status should still be reported in this case.
  20. ErrTaskRetry = errors.New("exec: task retry")
  21. // ErrTaskNoop returns when the a subsequent call to Do will not result in
  22. // advancing the task. Callers should avoid calling Do until the task has been updated.
  23. ErrTaskNoop = errors.New("exec: task noop")
  24. // ErrDependencyNotReady is returned if a given dependency can be accessed
  25. // through the Getter, but is not yet ready to be used. This is most
  26. // relevant for Volumes, which must be staged and published on the node.
  27. ErrDependencyNotReady error = errors.New("dependency not ready")
  28. )
  29. // ExitCoder is implemented by errors that have an exit code.
  30. type ExitCoder interface {
  31. // ExitCode returns the exit code.
  32. ExitCode() int
  33. }
  34. // Temporary indicates whether or not the error condition is temporary.
  35. //
  36. // If this is encountered in the controller, the failing operation will be
  37. // retried when this returns true. Otherwise, the operation is considered
  38. // fatal.
  39. type Temporary interface {
  40. Temporary() bool
  41. }
  42. // MakeTemporary makes the error temporary.
  43. func MakeTemporary(err error) error {
  44. if IsTemporary(err) {
  45. return err
  46. }
  47. return temporary{err}
  48. }
  49. type temporary struct {
  50. error
  51. }
  52. func (t temporary) Cause() error { return t.error }
  53. func (t temporary) Temporary() bool { return true }
  54. // IsTemporary returns true if the error or a recursive cause returns true for
  55. // temporary.
  56. func IsTemporary(err error) bool {
  57. if tmp, ok := err.(Temporary); ok && tmp.Temporary() {
  58. return true
  59. }
  60. cause := errors.Cause(err)
  61. if tmp, ok := cause.(Temporary); ok && tmp.Temporary() {
  62. return true
  63. }
  64. return false
  65. }