errors.go 1.9 KB

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