errors.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. errCDCWriteFailure = 0x1600
  17. errSyntax = 0x2000
  18. errUnauthorized = 0x2100
  19. errInvalid = 0x2200
  20. errConfig = 0x2300
  21. errAlreadyExists = 0x2400
  22. errUnprepared = 0x2500
  23. )
  24. type RequestError interface {
  25. Code() int
  26. Message() string
  27. Error() string
  28. }
  29. type errorFrame struct {
  30. frameHeader
  31. code int
  32. message string
  33. }
  34. func (e errorFrame) Code() int {
  35. return e.code
  36. }
  37. func (e errorFrame) Message() string {
  38. return e.message
  39. }
  40. func (e errorFrame) Error() string {
  41. return e.Message()
  42. }
  43. func (e errorFrame) String() string {
  44. return fmt.Sprintf("[error code=%x message=%q]", e.code, e.message)
  45. }
  46. type RequestErrUnavailable struct {
  47. errorFrame
  48. Consistency Consistency
  49. Required int
  50. Alive int
  51. }
  52. func (e *RequestErrUnavailable) String() string {
  53. return fmt.Sprintf("[request_error_unavailable consistency=%s required=%d alive=%d]", e.Consistency, e.Required, e.Alive)
  54. }
  55. type ErrorMap map[string]uint16
  56. type RequestErrWriteTimeout struct {
  57. errorFrame
  58. Consistency Consistency
  59. Received int
  60. BlockFor int
  61. WriteType string
  62. }
  63. type RequestErrWriteFailure struct {
  64. errorFrame
  65. Consistency Consistency
  66. Received int
  67. BlockFor int
  68. NumFailures int
  69. WriteType string
  70. ErrorMap ErrorMap
  71. }
  72. type RequestErrCDCWriteFailure struct {
  73. errorFrame
  74. }
  75. type RequestErrReadTimeout struct {
  76. errorFrame
  77. Consistency Consistency
  78. Received int
  79. BlockFor int
  80. DataPresent byte
  81. }
  82. type RequestErrAlreadyExists struct {
  83. errorFrame
  84. Keyspace string
  85. Table string
  86. }
  87. type RequestErrUnprepared struct {
  88. errorFrame
  89. StatementId []byte
  90. }
  91. type RequestErrReadFailure struct {
  92. errorFrame
  93. Consistency Consistency
  94. Received int
  95. BlockFor int
  96. NumFailures int
  97. DataPresent bool
  98. ErrorMap ErrorMap
  99. }
  100. type RequestErrFunctionFailure struct {
  101. errorFrame
  102. Keyspace string
  103. Function string
  104. ArgTypes []string
  105. }