errors.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 RequestErrWriteTimeout struct {
  56. errorFrame
  57. Consistency Consistency
  58. Received int
  59. BlockFor int
  60. WriteType string
  61. }
  62. type RequestErrWriteFailure struct {
  63. errorFrame
  64. Consistency Consistency
  65. Received int
  66. BlockFor int
  67. NumFailures int
  68. WriteType string
  69. }
  70. type RequestErrCDCWriteFailure struct {
  71. errorFrame
  72. }
  73. type RequestErrReadTimeout struct {
  74. errorFrame
  75. Consistency Consistency
  76. Received int
  77. BlockFor int
  78. DataPresent byte
  79. }
  80. type RequestErrAlreadyExists struct {
  81. errorFrame
  82. Keyspace string
  83. Table string
  84. }
  85. type RequestErrUnprepared struct {
  86. errorFrame
  87. StatementId []byte
  88. }
  89. type RequestErrReadFailure struct {
  90. errorFrame
  91. Consistency Consistency
  92. Received int
  93. BlockFor int
  94. NumFailures int
  95. DataPresent bool
  96. }
  97. type RequestErrFunctionFailure struct {
  98. errorFrame
  99. Keyspace string
  100. Function string
  101. ArgTypes []string
  102. }