errors.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. package gocql
  2. import "fmt"
  3. const (
  4. errServer = 0x0000
  5. errProtocol = 0x000A
  6. errCredentials = 0x0100
  7. errUnavailable = 0x1000
  8. errOverloaded = 0x1001
  9. errBootstrapping = 0x1002
  10. errTruncate = 0x1003
  11. errWriteTimeout = 0x1100
  12. errReadTimeout = 0x1200
  13. errReadFailure = 0x1300
  14. errFunctionFailure = 0x1400
  15. errWriteFailure = 0x1500
  16. errSyntax = 0x2000
  17. errUnauthorized = 0x2100
  18. errInvalid = 0x2200
  19. errConfig = 0x2300
  20. errAlreadyExists = 0x2400
  21. errUnprepared = 0x2500
  22. )
  23. type RequestError interface {
  24. Code() int
  25. Message() string
  26. Error() string
  27. }
  28. type errorFrame struct {
  29. frameHeader
  30. code int
  31. message string
  32. }
  33. func (e errorFrame) Code() int {
  34. return e.code
  35. }
  36. func (e errorFrame) Message() string {
  37. return e.message
  38. }
  39. func (e errorFrame) Error() string {
  40. return e.Message()
  41. }
  42. func (e errorFrame) String() string {
  43. return fmt.Sprintf("[error code=%x message=%q]", e.code, e.message)
  44. }
  45. type RequestErrUnavailable struct {
  46. errorFrame
  47. Consistency Consistency
  48. Required int
  49. Alive int
  50. }
  51. func (e *RequestErrUnavailable) String() string {
  52. return fmt.Sprintf("[request_error_unavailable consistency=%s required=%d alive=%d]", e.Consistency, e.Required, e.Alive)
  53. }
  54. type RequestErrWriteTimeout struct {
  55. errorFrame
  56. Consistency Consistency
  57. Received int
  58. BlockFor int
  59. WriteType string
  60. }
  61. type RequestErrWriteFailure struct {
  62. errorFrame
  63. Consistency Consistency
  64. Received int
  65. BlockFor int
  66. NumFailures int
  67. WriteType string
  68. }
  69. type RequestErrReadTimeout struct {
  70. errorFrame
  71. Consistency Consistency
  72. Received int
  73. BlockFor int
  74. DataPresent byte
  75. }
  76. type RequestErrAlreadyExists struct {
  77. errorFrame
  78. Keyspace string
  79. Table string
  80. }
  81. type RequestErrUnprepared struct {
  82. errorFrame
  83. StatementId []byte
  84. }
  85. type RequestErrReadFailure struct {
  86. errorFrame
  87. Consistency Consistency
  88. Received int
  89. BlockFor int
  90. NumFailures int
  91. DataPresent bool
  92. }
  93. type RequestErrFunctionFailure struct {
  94. errorFrame
  95. Keyspace string
  96. Function string
  97. ArgTypes []string
  98. }