-
Notifications
You must be signed in to change notification settings - Fork 104
/
Copy patherror.go
1126 lines (934 loc) · 33 KB
/
error.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
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package gocb
import (
"fmt"
"strings"
gocbcore "github.com/couchbase/gocbcore/v8"
"github.com/pkg/errors"
)
type retryAbleError interface {
retryable() bool
}
// KeyValueError represents an error that occurred while
// executing a K/V operation. Assumes that the service has returned a response.
type KeyValueError interface {
error
ID() string
StatusCode() int // ?
Opaque() uint32
KeyValueError() bool
}
// AuthenticationError represents an error caused by an authentication issue.
type AuthenticationError interface {
AuthenticationError() bool
}
// TemporaryFailureError represents an error that is temporary.
type TemporaryFailureError interface {
TemporaryFailureError() bool
}
// ServiceNotAvailableError represents that the service used for an operation is not available.
type ServiceNotAvailableError interface {
ServiceNotAvailableError() bool
}
type kvError struct {
id string
status gocbcore.StatusCode
description string
opaque uint32
context string
ref string
name string
isInsertOp bool
}
func (err kvError) Error() string {
if err.context != "" && err.ref != "" {
return fmt.Sprintf("%s (%s, context: %s, ref: %s)", err.description, err.name, err.context, err.ref)
} else if err.context != "" {
return fmt.Sprintf("%s (%s, context: %s)", err.description, err.name, err.context)
} else if err.ref != "" {
return fmt.Sprintf("%s (%s, ref: %s)", err.description, err.name, err.ref)
} else if err.name != "" && err.description != "" {
return fmt.Sprintf("%s (%s)", err.description, err.name)
} else if err.description != "" {
return err.description
}
return fmt.Sprintf("an unknown error occurred (%d)", err.status)
}
// StatusCode returns the memcached response status.
func (err kvError) StatusCode() int {
return int(err.status)
}
// ID returns the ID of the document used for the operation that yielded the error.
func (err kvError) ID() string {
return err.id
}
// Opaque is the unique identifier for the operation that yielded the error.
func (err kvError) Opaque() uint32 {
return err.opaque
}
// KeyValueError specifies whether or not this is a kvError.
func (err kvError) KeyValueError() bool {
return true
}
// AuthenticationError specifies whether or not this is an authentication error.
func (err kvError) AuthenticationError() bool {
return err.StatusCode() == int(gocbcore.StatusAuthError) ||
err.StatusCode() == int(gocbcore.StatusAccessError)
}
// TemporaryFailureError specifies whether or not this is a temporary error.
func (err kvError) TemporaryFailureError() bool {
return err.StatusCode() == int(gocbcore.StatusTmpFail) ||
err.StatusCode() == int(gocbcore.StatusOutOfMemory) ||
err.StatusCode() == int(gocbcore.StatusBusy)
}
// DurabilityError specifies whether or not this is a durability related error.
func (err kvError) DurabilityError() bool {
return err.StatusCode() == int(gocbcore.StatusSyncWriteAmbiguous) ||
err.StatusCode() == int(gocbcore.StatusSyncWriteInProgress) ||
err.StatusCode() == int(gocbcore.StatusDurabilityImpossible) ||
err.StatusCode() == int(gocbcore.StatusDurabilityInvalidLevel)
}
func (err kvError) retryable() bool {
return err.TemporaryFailureError()
}
// DurabilityError occurs when an error occurs during performing durability operations.
type DurabilityError interface {
DurabilityError() bool
}
type durabilityError struct {
reason string
}
func (err durabilityError) Error() string {
return err.reason
}
func (err durabilityError) DurabilityError() bool {
return true
}
// TimeoutError occurs when an operation times out.
type TimeoutError interface {
Timeout() bool
}
type timeoutError struct {
}
func (err timeoutError) Error() string {
return "operation timed out"
}
func (err timeoutError) Timeout() bool {
return true
}
type serviceNotAvailableError struct {
message string
}
func (e serviceNotAvailableError) Error() string {
return e.message
}
// ServiceNotAvailableError returns whether or not the error is a service not available error.
func (e serviceNotAvailableError) ServiceNotAvailableError() bool {
return true
}
// General Errors
// IsTemporaryFailureError indicates whether the passed error is a
// key-value "temporary failure, try again later" error.
func IsTemporaryFailureError(err error) bool {
cause := errors.Cause(err)
if tempErr, ok := cause.(TemporaryFailureError); ok && tempErr.TemporaryFailureError() {
return true
}
return false
}
// IsAuthenticationError verifies whether or not the cause for an error is an authentication error.
func IsAuthenticationError(err error) bool {
cause := errors.Cause(err)
if authErr, ok := cause.(AuthenticationError); ok && authErr.AuthenticationError() {
return true
}
return false
}
// IsServiceNotAvailableError indicates whether the passed error occurred due to
// the requested service not being available.
func IsServiceNotAvailableError(err error) bool {
switch errType := errors.Cause(err).(type) {
case ServiceNotAvailableError:
return errType.ServiceNotAvailableError()
default:
return false
}
}
// IsTimeoutError verifies whether or not the cause for an error is a timeout.
func IsTimeoutError(err error) bool {
switch errType := errors.Cause(err).(type) {
case TimeoutError:
return errType.Timeout()
default:
return false
}
}
// IsRetryableError indicates that the operation should be retried.
func IsRetryableError(err error) bool {
switch errType := errors.Cause(err).(type) {
case retryAbleError:
return errType.retryable()
default:
return false
}
}
// KV Specific Errors
// IsKeyValueError verifies whether or not the cause for an error is a KeyValueError.
func IsKeyValueError(err error) bool {
cause := errors.Cause(err)
if kvErr, ok := cause.(KeyValueError); ok && kvErr.KeyValueError() {
return true
}
return false
}
// IsScopeMissingError verifies whether or not the cause for an error is scope unknown.
func IsScopeMissingError(err error) bool {
cause := errors.Cause(err)
if kvErr, ok := cause.(KeyValueError); ok && kvErr.KeyValueError() {
return kvErr.StatusCode() == int(gocbcore.StatusScopeUnknown)
}
return false
}
// IsCollectionMissingError verifies whether or not the cause for an error is scope unknown.
func IsCollectionMissingError(err error) bool {
cause := errors.Cause(err)
if kvErr, ok := cause.(KeyValueError); ok && kvErr.KeyValueError() {
return kvErr.StatusCode() == int(gocbcore.StatusCollectionUnknown)
}
return false
}
// IsKeyExistsError indicates whether the passed error is a
// key-value "Key Already Exists" error.
func IsKeyExistsError(err error) bool {
cause := errors.Cause(err)
if kvErr, ok := cause.(KeyValueError); ok && kvErr.KeyValueError() {
return kvErr.StatusCode() == int(gocbcore.StatusKeyExists)
}
return false
}
// IsKeyNotFoundError indicates whether the passed error is a
// key-value "Key Not Found" error.
func IsKeyNotFoundError(err error) bool {
cause := errors.Cause(err)
if kvErr, ok := cause.(KeyValueError); ok && kvErr.KeyValueError() {
return kvErr.StatusCode() == int(gocbcore.StatusKeyNotFound)
}
return false
}
// IsValueTooLargeError indicates whether the passed error is a
// key-value "document value was too large" error.
func IsValueTooLargeError(err error) bool {
cause := errors.Cause(err)
if kvErr, ok := cause.(KeyValueError); ok && kvErr.KeyValueError() {
return kvErr.StatusCode() == int(gocbcore.StatusTooBig)
}
return false
}
// IsKeyLockedError indicates whether the passed error is a
// key-value operation failed due to the document being locked.
func IsKeyLockedError(err error) bool {
cause := errors.Cause(err)
if kvErr, ok := cause.(KeyValueError); ok && kvErr.KeyValueError() {
return kvErr.StatusCode() == int(gocbcore.StatusLocked)
}
return false
}
// IsInvalidArgumentsError indicates whether the passed error occurred due to
// // invalid arguments being passed to an operation.
func IsInvalidArgumentsError(err error) bool {
cause := errors.Cause(err)
if kvErr, ok := cause.(KeyValueError); ok && kvErr.KeyValueError() {
return kvErr.StatusCode() == int(gocbcore.StatusInvalidArgs)
}
return false
}
// IsBucketMissingError verifies whether or not the cause for an error is a bucket missing error.
func IsBucketMissingError(err error) bool {
cause := errors.Cause(err)
if kvErr, ok := cause.(KeyValueError); ok && kvErr.KeyValueError() {
return kvErr.StatusCode() == int(gocbcore.StatusNoBucket)
}
return false
}
// IsConfigurationError verifies whether or not the cause for an error is a configuration error.
func IsConfigurationError(err error) bool {
switch errType := errors.Cause(err).(type) {
case ConfigurationError:
return errType.ConfigurationError()
default:
return false
}
}
// IsCasMismatchError verifies whether or not the cause for an error is a cas mismatch.
func IsCasMismatchError(err error) bool {
cause := errors.Cause(err)
if kvErr, ok := cause.(kvError); ok && kvErr.KeyValueError() {
return kvErr.status == gocbcore.StatusKeyExists && kvErr.isInsertOp
}
return false
}
// KV Subdoc Specific Errors
// IsPathNotFoundError indicates whether the passed error is a
// key-value "sub-document path does not exist" error.
func IsPathNotFoundError(err error) bool {
cause := errors.Cause(err)
if kvErr, ok := cause.(KeyValueError); ok && kvErr.KeyValueError() {
return kvErr.StatusCode() == int(gocbcore.StatusSubDocPathNotFound)
}
return false
}
// IsPathMismatchError indicates whether the passed error occurred because
// the path component does not match the type of the element requested.
func IsPathMismatchError(err error) bool {
cause := errors.Cause(err)
if kvErr, ok := cause.(KeyValueError); ok && kvErr.KeyValueError() {
return kvErr.StatusCode() == int(gocbcore.StatusSubDocPathMismatch)
}
return false
}
// IsPathInvalidError indicates whether the passed error occurred because
// the path provided is invalid. For operations requiring an array index,
// this is returned if the last component of that path isn't an array.
// Similarly for operations requiring a dictionary, if the last component
// isn't a dictionary but eg. an array index.
func IsPathInvalidError(err error) bool {
cause := errors.Cause(err)
if kvErr, ok := cause.(KeyValueError); ok && kvErr.KeyValueError() {
return kvErr.StatusCode() == int(gocbcore.StatusSubDocPathInvalid)
}
return false
}
// IsPathTooDeepError indicates whether the passed error occurred because
// the path is too large (ie. the string is too long) or too deep
// (more than 32 components).
func IsPathTooDeepError(err error) bool {
cause := errors.Cause(err)
if kvErr, ok := cause.(KeyValueError); ok && kvErr.KeyValueError() {
return kvErr.StatusCode() == int(gocbcore.StatusSubDocPathTooBig)
}
return false
}
// IsDocumentTooDeepError indicates whether the passed error occurred because
// the target document's level of JSON nesting is too deep to be processed
// by the subdoc service.
func IsDocumentTooDeepError(err error) bool {
cause := errors.Cause(err)
if kvErr, ok := cause.(KeyValueError); ok && kvErr.KeyValueError() {
return kvErr.StatusCode() == int(gocbcore.StatusSubDocDocTooDeep)
}
return false
}
// IsCannotInsertValueError indicates whether the passed error occurred because
// the target document is not flagged or recognized as JSON.
func IsCannotInsertValueError(err error) bool {
cause := errors.Cause(err)
if kvErr, ok := cause.(KeyValueError); ok && kvErr.KeyValueError() {
return kvErr.StatusCode() == int(gocbcore.StatusSubDocCantInsert)
}
return false
}
// IsDocumentNotJsonEerror indicates whether the passed error occurred because
// the existing document is not valid JSON.
func IsDocumentNotJsonEerror(err error) bool {
cause := errors.Cause(err)
if kvErr, ok := cause.(KeyValueError); ok && kvErr.KeyValueError() {
return kvErr.StatusCode() == int(gocbcore.StatusSubDocNotJson)
}
return false
}
// IsNumRangeError indicates whether the passed error occurred because
// for arithmetic subdoc operations, the existing number is out of the valid range.
func IsNumRangeError(err error) bool {
cause := errors.Cause(err)
if kvErr, ok := cause.(KeyValueError); ok && kvErr.KeyValueError() {
return kvErr.StatusCode() == int(gocbcore.StatusSubDocBadRange)
}
return false
}
// IsDeltaRangeError indicates whether the passed error occurred because
// for arithmetic subdoc operations, the operation will make the value out of valid range.
func IsDeltaRangeError(err error) bool {
cause := errors.Cause(err)
if kvErr, ok := cause.(KeyValueError); ok && kvErr.KeyValueError() {
return kvErr.StatusCode() == int(gocbcore.StatusSubDocBadDelta)
}
return false
}
// IsPathExistsError indicates whether the passed error occurred because
// the last component of the path already exist despite the mutation operation
// expecting it not to exist (the mutation was expecting to create only the last part
// of the path and store the fragment there).
func IsPathExistsError(err error) bool {
cause := errors.Cause(err)
if kvErr, ok := cause.(KeyValueError); ok && kvErr.KeyValueError() {
return kvErr.StatusCode() == int(gocbcore.StatusSubDocPathExists)
}
return false
}
// IsSubDocInvalidArgumentsError indicates whether the passed error occurred because
// in a multi-specification, an invalid combination of commands were specified,
// including the case where too many paths were specified.
func IsSubDocInvalidArgumentsError(err error) bool {
cause := errors.Cause(err)
if kvErr, ok := cause.(KeyValueError); ok && kvErr.KeyValueError() {
return kvErr.StatusCode() == int(gocbcore.StatusSubDocBadCombo)
}
return false
}
// IsXattrUnknownMacroError indicates whether the passed error occurred because
// the server has no knowledge of the requested macro.
func IsXattrUnknownMacroError(err error) bool {
cause := errors.Cause(err)
if kvErr, ok := cause.(KeyValueError); ok && kvErr.KeyValueError() {
return kvErr.StatusCode() == int(gocbcore.StatusSubDocXattrUnknownMacro)
}
return false
}
// IsSubdocPathNotFoundError verifies whether or not the cause for an error is due to a subdoc operation path not found.
func IsSubdocPathNotFoundError(err error) bool {
cause := errors.Cause(err)
if kvErr, ok := cause.(KeyValueError); ok && kvErr.KeyValueError() {
return kvErr.StatusCode() == int(gocbcore.StatusSubDocPathNotFound)
}
return false
}
// IsSubdocPathExistsError verifies whether or not the cause for an error is due to a subdoc operation path exists
func IsSubdocPathExistsError(err error) bool {
cause := errors.Cause(err)
if kvErr, ok := cause.(KeyValueError); ok && kvErr.KeyValueError() {
return kvErr.StatusCode() == int(gocbcore.StatusSubDocPathExists)
}
return false
}
// Durability Specific Errors
// IsDurabilityError verifies whether or not the cause for an error is due to a durability error.
func IsDurabilityError(err error) bool {
switch errType := errors.Cause(err).(type) {
case DurabilityError:
return errType.DurabilityError()
default:
return false
}
}
// IsDurabilityLevelInvalidError verifies whether or not the cause for an error is because
// the requested durability level is invalid.
func IsDurabilityLevelInvalidError(err error) bool {
cause := errors.Cause(err)
if kvErr, ok := cause.(KeyValueError); ok && kvErr.KeyValueError() {
return kvErr.StatusCode() == int(gocbcore.StatusDurabilityInvalidLevel)
}
return false
}
// IsDurabilityImpossibleError verifies whether or not the cause for an error is because
// the requested durability level is impossible given the cluster topology due to insufficient replica servers.
func IsDurabilityImpossibleError(err error) bool {
cause := errors.Cause(err)
if kvErr, ok := cause.(KeyValueError); ok && kvErr.KeyValueError() {
return kvErr.StatusCode() == int(gocbcore.StatusDurabilityImpossible)
}
return false
}
// IsSyncWriteInProgressError verifies whether or not the cause for an error is because of an
// attempt to mutate a key which has a SyncWrite pending. Client should retry, possibly with backoff.
func IsSyncWriteInProgressError(err error) bool {
cause := errors.Cause(err)
if kvErr, ok := cause.(KeyValueError); ok && kvErr.KeyValueError() {
return kvErr.StatusCode() == int(gocbcore.StatusSyncWriteInProgress)
}
return false
}
// IsSyncWriteAmbiguousError verifies whether or not the cause for an error is because
// the client could not locate a replica within the cluster map or replica read. The bucket
// may not be configured to have replicas, which should be checked to ensure replica reads.
func IsSyncWriteAmbiguousError(err error) bool {
cause := errors.Cause(err)
if kvErr, ok := cause.(KeyValueError); ok && kvErr.KeyValueError() {
return kvErr.StatusCode() == int(gocbcore.StatusSyncWriteAmbiguous)
}
return false
}
// IsNoReplicasError verifies whether or not the cause for an error is because of an
// the client could not locate a replica within the cluster map or replica read. The Bucket may not be configured
// to have replicas, which should be checked to ensure replica reads.
func IsNoReplicasError(err error) bool {
cause := errors.Cause(err)
if cause == gocbcore.ErrNoReplicas {
return true
}
return false
}
// Service Specific Errors
// IsNoResultsError verifies whether or not the cause for an error is due no results being available to a query.
func IsNoResultsError(err error) bool {
switch errType := errors.Cause(err).(type) {
case NoResultsError:
return errType.NoResultsError()
default:
return false
}
}
// IsDesignDocumentNotFoundError occurs when a specific design document could not be found.
func IsDesignDocumentNotFoundError(err error) bool {
switch errType := errors.Cause(err).(type) {
case ViewIndexesError:
return errType.DesignDocumentNotFoundError()
default:
return false
}
}
// IsDesignDocumentExistsError occurs when a specific design document already exists.
func IsDesignDocumentExistsError(err error) bool {
switch errType := errors.Cause(err).(type) {
case ViewIndexesError:
return errType.DesignDocumentExistsError()
default:
return false
}
}
// IsDesignDocumentPublishDropFailError occurs when dropping a design document already exists.
func IsDesignDocumentPublishDropFailError(err error) bool {
switch errType := errors.Cause(err).(type) {
case ViewIndexesError:
return errType.DesignDocumentPublishDropFailError()
default:
return false
}
}
// IsBucketManagerBucketNotFoundError occurs when a specific bucket could not be found.
func IsBucketManagerBucketNotFoundError(err error) bool {
switch errType := errors.Cause(err).(type) {
case BucketManagerError:
return errType.BucketNotFoundError()
default:
return false
}
}
// IsBucketManagerBucketExistsError occurs when a specific bucket already exists.
func IsBucketManagerBucketExistsError(err error) bool {
switch errType := errors.Cause(err).(type) {
case BucketManagerError:
return errType.BucketExistsError()
default:
return false
}
}
// HTTPError indicates that an error occurred with a valid HTTP response for an operation.
type HTTPError interface {
HTTPStatus() int
}
type clientError struct {
message string
}
func (e clientError) Error() string {
return e.message
}
// ProjectionErrors is a collection of one or more KeyValueError that occurs during a Get with projections operation.
type ProjectionErrors interface {
error
Errors() []KeyValueError
ProjectionErrors() bool
}
type projectionErrors struct {
errors []KeyValueError
}
func (e projectionErrors) ProjectionErrors() bool {
return true
}
func (e projectionErrors) Error() string {
var errs []string
for _, err := range e.errors {
errs = append(errs, err.Error())
}
return strings.Join(errs, ", ")
}
// ViewQueryError is the error type for an error that occurs during view query execution.
type ViewQueryError interface {
error
Reason() string
Message() string
}
type viewError struct {
ErrorMessage string `json:"message"`
ErrorReason string `json:"reason"`
}
func (e viewError) Error() string {
return e.ErrorMessage + " - " + e.ErrorReason
}
// Reason is the reason for the error occurring.
func (e viewError) Reason() string {
return e.ErrorReason
}
// Message contains any message from the server for this error.
func (e viewError) Message() string {
return e.ErrorMessage
}
// ViewQueryErrors is a collection of one or more ViewQueryError that occurs for errors created by Couchbase Server
// during View query execution.
type ViewQueryErrors interface {
error
Errors() []ViewQueryError
HTTPStatus() int
Endpoint() string
}
type viewMultiError struct {
errors []ViewQueryError
httpStatus int
endpoint string
partial bool
}
func (e viewMultiError) Error() string {
var errs []string
for _, err := range e.errors {
errs = append(errs, err.Error())
}
return strings.Join(errs, ", ")
}
// HTTPStatus returns the HTTP status code for the operation.
func (e viewMultiError) HTTPStatus() int {
return e.httpStatus
}
// Endpoint returns the endpoint that was used for the operation.
func (e viewMultiError) Endpoint() string {
return e.endpoint
}
// Errors returns the list of ViewQueryErrors.
func (e viewMultiError) Errors() []ViewQueryError {
return e.errors
}
// AnalyticsQueryError occurs for errors created by Couchbase Server during Analytics query execution.
type AnalyticsQueryError interface {
error
Code() uint32
Message() string
HTTPStatus() int
Endpoint() string
ContextID() string
}
type analyticsQueryError struct {
ErrorCode uint32 `json:"code"`
ErrorMessage string `json:"msg"`
httpStatus int
endpoint string
contextID string
}
func (e analyticsQueryError) Error() string {
return fmt.Sprintf("[%d] %s", e.ErrorCode, e.ErrorMessage)
}
// Code returns the error code for this error.
func (e analyticsQueryError) Code() uint32 {
return e.ErrorCode
}
// Message returns any message from the server for this error.
func (e analyticsQueryError) Message() string {
return e.ErrorMessage
}
func (e analyticsQueryError) retryable() bool {
if e.Code() == 21002 || e.Code() == 23000 || e.Code() == 23003 || e.Code() == 23007 {
return true
}
return false
}
// Timeout indicates whether or not this error is a timeout.
func (e analyticsQueryError) Timeout() bool {
if e.ErrorCode == 21002 {
return true
}
return false
}
// HTTPStatus returns the HTTP status code for the operation.
func (e analyticsQueryError) HTTPStatus() int {
return e.httpStatus
}
// Endpoint returns the endpoint that was used for the operation.
func (e analyticsQueryError) Endpoint() string {
return e.endpoint
}
// ContextID returns the context ID that was used for the operation.
func (e analyticsQueryError) ContextID() string {
return e.contextID
}
// QueryError occurs for errors created by Couchbase Server during N1ql query execution.
type QueryError interface {
error
Code() uint32
Message() string
HTTPStatus() int
Endpoint() string
ContextID() string
}
type queryError struct {
ErrorCode uint32 `json:"code"`
ErrorMessage string `json:"msg"`
httpStatus int
endpoint string
contextID string
enhancedStmtSupported bool
}
func (e queryError) Error() string {
return fmt.Sprintf("[%d] %s", e.ErrorCode, e.ErrorMessage)
}
// Code returns the error code for this error.
func (e queryError) Code() uint32 {
return e.ErrorCode
}
// Message returns any message from the server for this error.
func (e queryError) Message() string {
return e.ErrorMessage
}
func (e queryError) retryable() bool {
if e.enhancedStmtSupported {
if e.ErrorCode == 4040 {
return true
}
return false
}
if e.ErrorCode == 4050 || e.ErrorCode == 4070 || e.ErrorCode == 5000 {
return true
}
return false
}
// Timeout indicates whether or not this error is a timeout.
func (e queryError) Timeout() bool {
if e.ErrorCode == 1080 {
return true
}
return false
}
// HTTPStatus returns the HTTP status code for the operation.
func (e queryError) HTTPStatus() int {
return e.httpStatus
}
// Endpoint returns the endpoint that was used for the operation.
func (e queryError) Endpoint() string {
return e.endpoint
}
// ContextID returns the context ID that was used for the operation.
func (e queryError) ContextID() string {
return e.contextID
}
// SearchError occurs for errors created by Couchbase Server during Search query execution.
type SearchError interface {
error
Message() string
}
type searchError struct {
message string
}
func (e searchError) Error() string {
return e.message
}
// Message returns any message from the server for this error.
func (e searchError) Message() string {
return e.message
}
// SearchErrors is a collection of one or more SearchError that occurs for errors created by Couchbase Server
// during Search query execution.
type SearchErrors interface {
error
Errors() []SearchError
HTTPStatus() int
Endpoint() string
ContextID() string
}
type searchMultiError struct {
errors []SearchError
httpStatus int
endpoint string
contextID string
}
func (e searchMultiError) Error() string {
var errs []string
for _, err := range e.errors {
errs = append(errs, err.Error())
}
return strings.Join(errs, ", ")
}
// HTTPStatus returns the HTTP status code for the operation.
func (e searchMultiError) HTTPStatus() int {
return e.httpStatus
}
// Endpoint returns the endpoint that was used for the operation.
func (e searchMultiError) Endpoint() string {
return e.endpoint
}
// ContextID returns the context ID that was used for the operation.
func (e searchMultiError) ContextID() string {
return e.contextID
}
// Errors returns the list of SearchErrors.
func (e searchMultiError) Errors() []SearchError {
return e.errors
}
// PartialResults indicates whether or not the operation also yielded results.
func (e searchMultiError) retryable() bool {
return e.httpStatus == 419
}
// ConfigurationError occurs when the client is configured incorrectly.
type ConfigurationError interface {
error
ConfigurationError() bool
}
type configurationError struct {
message string
}
func (e configurationError) Error() string {
return e.message
}
// ConfigurationError indicates whether or not this error is a ConfigurationError
func (e configurationError) ConfigurationError() bool {
return true
}
// ErrorCause returns the underlying cause of an error.
func ErrorCause(err error) error {
return errors.Cause(err)
}
// NoResultsError occurs when when no results are available to a query.
type NoResultsError interface {
error
NoResultsError() bool
}
type noResultsError struct {
}
func (e noResultsError) Error() string {
return "No results returned."
}
// NoResultsError indicates whether or not this error is a NoResultsError
func (e noResultsError) NoResultsError() bool {
return true
}
// ViewIndexesError occurs for errors created By Couchbase Server when performing index management.
type ViewIndexesError interface {
error
HTTPStatus() int
DesignDocumentNotFoundError() bool
DesignDocumentExistsError() bool
DesignDocumentPublishDropFailError() bool
}
type viewIndexError struct {
statusCode int
message string
indexMissing bool
indexExists bool
publishDropFail bool
}
func (e viewIndexError) Error() string {
return e.message
}
// HTTPStatus returns the HTTP status code for the operation.
func (e viewIndexError) HTTPStatus() int {
return e.statusCode
}
// DesignDocumentNotFoundError indicates that a design document could not be found.
func (e viewIndexError) DesignDocumentNotFoundError() bool {
return e.indexMissing
}
// DesignDocumentExistsError indicates that a design document already exists.