forked from ravendb/ravendb-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.go
639 lines (548 loc) · 14.6 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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
package ravendb
import (
"fmt"
"strings"
)
type CancellationError struct {
}
func (e *CancellationError) Error() string {
return "CancellationError"
}
type errorBase struct {
wrapped error
ErrorStr string
}
// Error makes it conform to error interface
func (e *errorBase) Error() string {
return e.ErrorStr
}
// hackish way to get a wrapped error
func (e *errorBase) WrappedError() error {
return e.wrapped
}
type iWrappedError interface {
WrappedError() error
}
// GetWrappedError returns an error wrapped by this error
// If no error is wrapped, returns nil
func GetWrappedError(err error) error {
if e, ok := err.(iWrappedError); ok {
return e.WrappedError()
}
return nil
}
func (e *errorBase) setErrorf(format string, args ...interface{}) {
if len(args) == 0 {
e.ErrorStr = format
return
}
// a bit of a hack: to make it easy to port Java code, if the last
// argument is of type error, we consider it a wrapped error
n := len(args)
last := args[n-1]
if err, ok := last.(error); ok {
e.wrapped = err
args = args[:n-1]
}
e.ErrorStr = fmt.Sprintf(format, args...)
}
// RuntimeError represents generic runtime error
type RuntimeError struct {
errorBase
}
func newRuntimeError(format string, args ...interface{}) *RuntimeError {
res := &RuntimeError{}
res.setErrorf(format, args...)
return res
}
// UnsupportedOperationError represents unsupported operation error
type UnsupportedOperationError struct {
errorBase
}
func newUnsupportedOperationError(format string, args ...interface{}) *UnsupportedOperationError {
res := &UnsupportedOperationError{}
res.setErrorf(format, args...)
return res
}
// IllegalStateError represents illegal state error
type IllegalStateError struct {
errorBase
}
func newIllegalStateError(format string, args ...interface{}) *IllegalStateError {
res := &IllegalStateError{}
res.setErrorf(format, args...)
return res
}
// IllegalArgumentError represents illegal argument error
type IllegalArgumentError struct {
errorBase
}
func newIllegalArgumentError(format string, args ...interface{}) *IllegalArgumentError {
res := &IllegalArgumentError{}
res.setErrorf(format, args...)
return res
}
// NotImplementedError represents not implemented error
type NotImplementedError struct {
errorBase
}
func newNotImplementedError(format string, args ...interface{}) *NotImplementedError {
res := &NotImplementedError{}
res.setErrorf(format, args...)
return res
}
// AllTopologyNodesDownError represents "all topology nodes are down" error
type AllTopologyNodesDownError struct {
errorBase
}
func newAllTopologyNodesDownError(format string, args ...interface{}) *AllTopologyNodesDownError {
res := &AllTopologyNodesDownError{}
res.setErrorf(format, args...)
return res
}
// OperationCancelledError represents "operation cancelled" error
type OperationCancelledError struct {
errorBase
}
func newOperationCancelledError(format string, args ...interface{}) *OperationCancelledError {
res := &OperationCancelledError{}
res.setErrorf(format, args...)
return res
}
// AuthorizationError represents authorization error
type AuthorizationError struct {
errorBase
}
func newAuthorizationError(format string, args ...interface{}) *AuthorizationError {
res := &AuthorizationError{}
res.setErrorf(format, args...)
return res
}
// RavenError represents generic raven error
// all exceptions that in Java extend RavenException should
// contain this error
type RavenError struct {
errorBase
}
// hackish way to see if "inherits" from (embeds) RavenError
func (e *RavenError) isRavenError() bool {
return true
}
type iRavenError interface {
isRavenError() bool
}
func isRavenError(err error) bool {
_, ok := err.(iRavenError)
return ok
}
func newRavenError(format string, args ...interface{}) *RavenError {
res := &RavenError{}
res.setErrorf(format, args...)
return res
}
// ConcurrencyError represents concurrency error
type ConcurrencyError struct {
RavenError
ExpectedETag int64
ActualETag int64
ExpectedChangeVector string
ActualChangeVector string
}
func newConcurrencyError(format string, args ...interface{}) *ConcurrencyError {
res := &ConcurrencyError{}
res.setErrorf(format, args...)
return res
}
// NonUniqueObjectError represents non unique object error
type NonUniqueObjectError struct {
RavenError
}
// newNonUniqueObjectError creates new NonUniqueObjectError
func newNonUniqueObjectError(format string, args ...interface{}) *NonUniqueObjectError {
res := &NonUniqueObjectError{}
res.setErrorf(format, args...)
return res
}
// DatabaseDoesNotExistError represents "database not not exist" error
type DatabaseDoesNotExistError struct {
RavenError
}
// newDatabaseDoesNotExistError creates new NonUniqueObjectError
func newDatabaseDoesNotExistError(format string, args ...interface{}) *DatabaseDoesNotExistError {
res := &DatabaseDoesNotExistError{}
res.setErrorf(format, args...)
return res
}
// TimeoutError represents timeout error
type TimeoutError struct {
RavenError
}
// NewTimeoutError returns new TimeoutError
func NewTimeoutError(format string, args ...interface{}) *TimeoutError {
res := &TimeoutError{}
res.setErrorf(format, args...)
return res
}
// IndexDoesNotExistError represents "index doesn't exist" error
type IndexDoesNotExistError struct {
RavenError
}
func newIndexDoesNotExistError(format string, args ...interface{}) *IndexDoesNotExistError {
res := &IndexDoesNotExistError{}
res.setErrorf(format, args...)
return res
}
// BadResponseError represents "bad response" error
type BadResponseError struct {
RavenError
}
func newBadResponseError(format string, args ...interface{}) *BadResponseError {
res := &BadResponseError{}
res.setErrorf(format, args...)
return res
}
// BadRequestError maps to server's 400 Bad Request response
// This is additional information sent by the server
type BadRequestError struct {
RavenError
}
// ConflictError maps to server's 409 Conflict response
type ConflictError struct {
RavenError
}
func newConflictError(format string, args ...interface{}) *ConflictError {
res := &ConflictError{}
res.setErrorf(format, args...)
return res
}
// a base type for subscription-related errors
type SubscriptionError struct {
RavenError
}
// SubscriberErrorError represents error about subscriber error
// Note: name is unfortunate but it corresponds to Java's SubscriberErrorException
type SubscriberErrorError struct {
SubscriptionError
}
// SubscriptionChangeVectorUpdateConcurrencyError represents an error about
// subscription change vector update concurrency
type SubscriptionChangeVectorUpdateConcurrencyError struct {
SubscriptionError
}
func newSubscriptionChangeVectorUpdateConcurrencyError(format string, args ...interface{}) *SubscriptionChangeVectorUpdateConcurrencyError {
res := &SubscriptionChangeVectorUpdateConcurrencyError{}
res.setErrorf(format, args...)
return res
}
// SubscriptionClosedError is returned when subscription is closed
type SubscriptionClosedError struct {
SubscriptionError
}
func newSubscriptionClosedError(format string, args ...interface{}) *SubscriptionClosedError {
res := &SubscriptionClosedError{}
res.setErrorf(format, args...)
return res
}
// SubscriptionDoesNotBelongToNodeError is returned when subscription
// does not belong to node
type SubscriptionDoesNotBelongToNodeError struct {
SubscriptionError
appropriateNode string
}
func newSubscriptionDoesNotBelongToNodeError(format string, args ...interface{}) *SubscriptionDoesNotBelongToNodeError {
res := &SubscriptionDoesNotBelongToNodeError{}
res.setErrorf(format, args...)
return res
}
// SubscriptionDoesNotExistError is returned when subscription doesn't exist
type SubscriptionDoesNotExistError struct {
SubscriptionError
}
func newSubscriptionDoesNotExistError(format string, args ...interface{}) *SubscriptionDoesNotExistError {
res := &SubscriptionDoesNotExistError{}
res.setErrorf(format, args...)
return res
}
// SubscriptionInvalidStateError is returned when subscription is in invalid state
type SubscriptionInvalidStateError struct {
SubscriptionError
}
func newSubscriptionInvalidStateError(format string, args ...interface{}) *SubscriptionInvalidStateError {
res := &SubscriptionInvalidStateError{}
res.setErrorf(format, args...)
return res
}
// SubscriptionInUseError is returned when subscription is in use
type SubscriptionInUseError struct {
SubscriptionError
}
func newSubscriptionInUseError(format string, args ...interface{}) *SubscriptionInUseError {
res := &SubscriptionInUseError{}
res.setErrorf(format, args...)
return res
}
// ClientVersionMismatchError is returned when subscription is in use
type ClientVersionMismatchError struct {
RavenError
}
// CertificateNameMismatchError is returned when subscription is in use
type CertificateNameMismatchError struct {
errorBase
}
func throwCancellationRequested() error {
return newOperationCancelledError("")
}
type InvalidQueryError struct {
RavenError
}
type UnsuccessfulRequestError struct {
RavenError
}
type ChangeProcessingError struct {
RavenError
}
type CommandExecutionError struct {
RavenError
}
type NodeIsPassiveError struct {
RavenError
}
type NoLeaderError struct {
RavenError
}
type LicenseActivationError struct {
RavenError
}
type CompilationError struct {
RavenError
}
type DatabaseConcurrentLoadTimeoutError struct {
RavenError
}
type DatabaseDisabledError struct {
RavenError
}
type DatabaseLoadFailureError struct {
RavenError
}
type DatabaseLoadTimeoutError struct {
RavenError
}
type DatabaseNotRelevantError struct {
RavenError
}
type DocumentDoesNotExistError struct {
RavenError
}
type BulkInsertProtocolViolationError struct {
RavenError
}
type IndexAlreadyExistError struct {
RavenError
}
type IndexCreationError struct {
RavenError
}
type IndexDeletionError struct {
RavenError
}
type IndexInvalidError struct {
RavenError
}
type JavaScriptError struct {
RavenError
}
type RevisionsDisabledError struct {
RavenError
}
type RouteNotFoundError struct {
RavenError
}
type SecurityError struct {
RavenError
}
type ServerLoadFailureError struct {
RavenError
}
type IndexCompilationError struct {
RavenError
}
func makeRavenErrorFromName(exceptionName string, errMsg string) error {
// Java's "FooException" is "FooError" in Go
s := strings.Replace(exceptionName, "Exception", "Error", -1)
switch s {
case "IndexCompilationError":
res := &IndexCompilationError{}
res.ErrorStr = errMsg
return res
case "ConcurrencyError":
res := &ConcurrencyError{}
res.ErrorStr = errMsg
return res
case "NonUniqueObjectError":
res := &NonUniqueObjectError{}
res.ErrorStr = errMsg
return res
case "DatabaseDoesNotExistError":
res := &DatabaseDoesNotExistError{}
res.ErrorStr = errMsg
return res
case "TimeoutError":
res := &TimeoutError{}
res.ErrorStr = errMsg
return res
case "IndexDoesNotExistError":
res := &IndexDoesNotExistError{}
res.ErrorStr = errMsg
return res
case "BadResponseError":
res := &BadResponseError{}
res.ErrorStr = errMsg
return res
case "BadRequestError":
res := &BadRequestError{}
res.ErrorStr = errMsg
return res
case "ConflictError":
res := &ConflictError{}
res.ErrorStr = errMsg
return res
case "SubscriberErrorError":
res := &SubscriberErrorError{}
res.ErrorStr = errMsg
return res
case "SubscriptionChangeVectorUpdateConcurrencyError":
res := &SubscriptionChangeVectorUpdateConcurrencyError{}
res.ErrorStr = errMsg
return res
case "SubscriptionClosedError":
res := &SubscriptionClosedError{}
res.ErrorStr = errMsg
return res
case "SubscriptionDoesNotBelongToNodeError":
res := &SubscriptionDoesNotBelongToNodeError{}
res.ErrorStr = errMsg
return res
case "SubscriptionDoesNotExistError":
res := &SubscriptionDoesNotExistError{}
res.ErrorStr = errMsg
return res
case "SubscriptionInvalidStateError":
res := &SubscriptionInvalidStateError{}
res.ErrorStr = errMsg
return res
case "SubscriptionInUseError":
res := &SubscriptionInUseError{}
res.ErrorStr = errMsg
return res
case "ClientVersionMismatchError":
res := &ClientVersionMismatchError{}
res.ErrorStr = errMsg
return res
case "CertificateNameMismatchError":
res := &CertificateNameMismatchError{}
res.ErrorStr = errMsg
return res
case "InvalidQueryError":
res := &InvalidQueryError{}
res.ErrorStr = errMsg
return res
case "UnsuccessfulRequestError":
res := &UnsuccessfulRequestError{}
res.ErrorStr = errMsg
return res
case "ChangeProcessingError":
res := &ChangeProcessingError{}
res.ErrorStr = errMsg
return res
case "CommandExecutionError":
res := &CommandExecutionError{}
res.ErrorStr = errMsg
return res
case "NodeIsPassiveError":
res := &NodeIsPassiveError{}
res.ErrorStr = errMsg
return res
case "NoLeaderError":
res := &NoLeaderError{}
res.ErrorStr = errMsg
return res
case "LicenseActivationError":
res := &LicenseActivationError{}
res.ErrorStr = errMsg
return res
case "CompilationError":
res := &CompilationError{}
res.ErrorStr = errMsg
return res
case "DatabaseConcurrentLoadTimeoutError":
res := &DatabaseConcurrentLoadTimeoutError{}
res.ErrorStr = errMsg
return res
case "DatabaseDisabledError":
res := &DatabaseDisabledError{}
res.ErrorStr = errMsg
return res
case "DatabaseLoadFailureError":
res := &DatabaseLoadFailureError{}
res.ErrorStr = errMsg
return res
case "DatabaseLoadTimeoutError":
res := &DatabaseLoadTimeoutError{}
res.ErrorStr = errMsg
return res
case "DatabaseNotRelevantError":
res := &DatabaseNotRelevantError{}
res.ErrorStr = errMsg
return res
case "DocumentDoesNotExistError":
res := &DocumentDoesNotExistError{}
res.ErrorStr = errMsg
return res
case "BulkInsertAbortedError":
res := &BulkInsertAbortedError{}
res.ErrorStr = errMsg
return res
case "BulkInsertProtocolViolationError":
res := &BulkInsertProtocolViolationError{}
res.ErrorStr = errMsg
return res
case "IndexAlreadyExistError":
res := &IndexAlreadyExistError{}
res.ErrorStr = errMsg
return res
case "IndexCreationError":
res := &IndexCreationError{}
res.ErrorStr = errMsg
return res
case "IndexDeletionError":
res := &IndexDeletionError{}
res.ErrorStr = errMsg
return res
case "IndexInvalidError":
res := &IndexInvalidError{}
res.ErrorStr = errMsg
return res
case "JavaScriptError":
res := &JavaScriptError{}
res.ErrorStr = errMsg
return res
case "RevisionsDisabledError":
res := &RevisionsDisabledError{}
res.ErrorStr = errMsg
return res
case "RouteNotFoundError":
res := &RouteNotFoundError{}
res.ErrorStr = errMsg
return res
case "SecurityError":
res := &SecurityError{}
res.ErrorStr = errMsg
return res
case "ServerLoadFailureError":
res := &ServerLoadFailureError{}
res.ErrorStr = errMsg
return res
}
return nil
}