error.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package libcontainer
  2. import "io"
  3. // API error code type.
  4. type ErrorCode int
  5. // API error codes.
  6. const (
  7. // Factory errors
  8. IdInUse ErrorCode = iota
  9. InvalidIdFormat
  10. // Container errors
  11. ContainerNotExists
  12. ContainerPaused
  13. ContainerNotStopped
  14. ContainerNotRunning
  15. ContainerNotPaused
  16. // Process errors
  17. NoProcessOps
  18. // Common errors
  19. ConfigInvalid
  20. ConsoleExists
  21. SystemError
  22. )
  23. func (c ErrorCode) String() string {
  24. switch c {
  25. case IdInUse:
  26. return "Id already in use"
  27. case InvalidIdFormat:
  28. return "Invalid format"
  29. case ContainerPaused:
  30. return "Container paused"
  31. case ConfigInvalid:
  32. return "Invalid configuration"
  33. case SystemError:
  34. return "System error"
  35. case ContainerNotExists:
  36. return "Container does not exist"
  37. case ContainerNotStopped:
  38. return "Container is not stopped"
  39. case ContainerNotRunning:
  40. return "Container is not running"
  41. case ConsoleExists:
  42. return "Console exists for process"
  43. case ContainerNotPaused:
  44. return "Container is not paused"
  45. case NoProcessOps:
  46. return "No process operations"
  47. default:
  48. return "Unknown error"
  49. }
  50. }
  51. // API Error type.
  52. type Error interface {
  53. error
  54. // Returns a verbose string including the error message
  55. // and a representation of the stack trace suitable for
  56. // printing.
  57. Detail(w io.Writer) error
  58. // Returns the error code for this error.
  59. Code() ErrorCode
  60. }