forked from apache/cassandra-gocql-driver
-
Notifications
You must be signed in to change notification settings - Fork 59
/
errors.go
223 lines (198 loc) · 6.58 KB
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
package gocql
import "fmt"
// See CQL Binary Protocol v5, section 8 for more details.
// https://github.com/apache/cassandra/blob/7337fc0/doc/native_protocol_v5.spec
const (
// ErrCodeServer indicates unexpected error on server-side.
//
// See https://github.com/apache/cassandra/blob/7337fc0/doc/native_protocol_v5.spec#L1246-L1247
ErrCodeServer = 0x0000
// ErrCodeProtocol indicates a protocol violation by some client message.
//
// See https://github.com/apache/cassandra/blob/7337fc0/doc/native_protocol_v5.spec#L1248-L1250
ErrCodeProtocol = 0x000A
// ErrCodeCredentials indicates missing required authentication.
//
// See https://github.com/apache/cassandra/blob/7337fc0/doc/native_protocol_v5.spec#L1251-L1254
ErrCodeCredentials = 0x0100
// ErrCodeUnavailable indicates unavailable error.
//
// See https://github.com/apache/cassandra/blob/7337fc0/doc/native_protocol_v5.spec#L1255-L1265
ErrCodeUnavailable = 0x1000
// ErrCodeOverloaded returned in case of request on overloaded node coordinator.
//
// See https://github.com/apache/cassandra/blob/7337fc0/doc/native_protocol_v5.spec#L1266-L1267
ErrCodeOverloaded = 0x1001
// ErrCodeBootstrapping returned from the coordinator node in bootstrapping phase.
//
// See https://github.com/apache/cassandra/blob/7337fc0/doc/native_protocol_v5.spec#L1268-L1269
ErrCodeBootstrapping = 0x1002
// ErrCodeTruncate indicates truncation exception.
//
// See https://github.com/apache/cassandra/blob/7337fc0/doc/native_protocol_v5.spec#L1270
ErrCodeTruncate = 0x1003
// ErrCodeWriteTimeout returned in case of timeout during the request write.
//
// See https://github.com/apache/cassandra/blob/7337fc0/doc/native_protocol_v5.spec#L1271-L1304
ErrCodeWriteTimeout = 0x1100
// ErrCodeReadTimeout returned in case of timeout during the request read.
//
// See https://github.com/apache/cassandra/blob/7337fc0/doc/native_protocol_v5.spec#L1305-L1321
ErrCodeReadTimeout = 0x1200
// ErrCodeReadFailure indicates request read error which is not covered by ErrCodeReadTimeout.
//
// See https://github.com/apache/cassandra/blob/7337fc0/doc/native_protocol_v5.spec#L1322-L1340
ErrCodeReadFailure = 0x1300
// ErrCodeFunctionFailure indicates an error in user-defined function.
//
// See https://github.com/apache/cassandra/blob/7337fc0/doc/native_protocol_v5.spec#L1341-L1347
ErrCodeFunctionFailure = 0x1400
// ErrCodeWriteFailure indicates request write error which is not covered by ErrCodeWriteTimeout.
//
// See https://github.com/apache/cassandra/blob/7337fc0/doc/native_protocol_v5.spec#L1348-L1385
ErrCodeWriteFailure = 0x1500
// ErrCodeCDCWriteFailure is defined, but not yet documented in CQLv5 protocol.
//
// See https://github.com/apache/cassandra/blob/7337fc0/doc/native_protocol_v5.spec#L1386
ErrCodeCDCWriteFailure = 0x1600
// ErrCodeCASWriteUnknown indicates only partially completed CAS operation.
//
// See https://github.com/apache/cassandra/blob/7337fc0/doc/native_protocol_v5.spec#L1387-L1397
ErrCodeCASWriteUnknown = 0x1700
// ErrCodeSyntax indicates the syntax error in the query.
//
// See https://github.com/apache/cassandra/blob/7337fc0/doc/native_protocol_v5.spec#L1399
ErrCodeSyntax = 0x2000
// ErrCodeUnauthorized indicates access rights violation by user on performed operation.
//
// See https://github.com/apache/cassandra/blob/7337fc0/doc/native_protocol_v5.spec#L1400-L1401
ErrCodeUnauthorized = 0x2100
// ErrCodeInvalid indicates invalid query error which is not covered by ErrCodeSyntax.
//
// See https://github.com/apache/cassandra/blob/7337fc0/doc/native_protocol_v5.spec#L1402
ErrCodeInvalid = 0x2200
// ErrCodeConfig indicates the configuration error.
//
// See https://github.com/apache/cassandra/blob/7337fc0/doc/native_protocol_v5.spec#L1403
ErrCodeConfig = 0x2300
// ErrCodeAlreadyExists is returned for the requests creating the existing keyspace/table.
//
// See https://github.com/apache/cassandra/blob/7337fc0/doc/native_protocol_v5.spec#L1404-L1413
ErrCodeAlreadyExists = 0x2400
// ErrCodeUnprepared returned from the host for prepared statement which is unknown.
//
// See https://github.com/apache/cassandra/blob/7337fc0/doc/native_protocol_v5.spec#L1414-L1417
ErrCodeUnprepared = 0x2500
)
type RequestError interface {
Code() int
Message() string
Error() string
}
type errorFrame struct {
frameHeader
code int
message string
}
func (e errorFrame) Code() int {
return e.code
}
func (e errorFrame) Message() string {
return e.message
}
func (e errorFrame) Error() string {
return e.Message()
}
func (e errorFrame) String() string {
return fmt.Sprintf("[error code=%x message=%q]", e.code, e.message)
}
type RequestErrUnavailable struct {
errorFrame
Consistency Consistency
Required int
Alive int
}
func (e *RequestErrUnavailable) String() string {
return fmt.Sprintf("[request_error_unavailable consistency=%s required=%d alive=%d]", e.Consistency, e.Required, e.Alive)
}
type ErrorMap map[string]uint16
type RequestErrWriteTimeout struct {
errorFrame
Consistency Consistency
Received int
BlockFor int
WriteType string
}
type RequestErrWriteFailure struct {
errorFrame
Consistency Consistency
Received int
BlockFor int
NumFailures int
WriteType string
ErrorMap ErrorMap
}
type RequestErrCDCWriteFailure struct {
errorFrame
}
type RequestErrReadTimeout struct {
errorFrame
Consistency Consistency
Received int
BlockFor int
DataPresent byte
}
type RequestErrAlreadyExists struct {
errorFrame
Keyspace string
Table string
}
type RequestErrUnprepared struct {
errorFrame
StatementId []byte
}
type RequestErrReadFailure struct {
errorFrame
Consistency Consistency
Received int
BlockFor int
NumFailures int
DataPresent bool
ErrorMap ErrorMap
}
type RequestErrFunctionFailure struct {
errorFrame
Keyspace string
Function string
ArgTypes []string
}
// RequestErrCASWriteUnknown is distinct error for ErrCodeCasWriteUnknown.
//
// See https://github.com/apache/cassandra/blob/7337fc0/doc/native_protocol_v5.spec#L1387-L1397
type RequestErrCASWriteUnknown struct {
errorFrame
Consistency Consistency
Received int
BlockFor int
}
type OpType uint8
const (
OpTypeRead OpType = 0
OpTypeWrite OpType = 1
)
type RequestErrRateLimitReached struct {
errorFrame
OpType OpType
RejectedByCoordinator bool
}
func (e *RequestErrRateLimitReached) String() string {
var opType string
if e.OpType == OpTypeRead {
opType = "Read"
} else if e.OpType == OpTypeWrite {
opType = "Write"
} else {
opType = "Other"
}
return fmt.Sprintf("[request_error_rate_limit_reached OpType=%s RejectedByCoordinator=%t]", opType, e.RejectedByCoordinator)
}