-
Notifications
You must be signed in to change notification settings - Fork 104
/
error_wrapping.go
102 lines (92 loc) · 3.18 KB
/
error_wrapping.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
package gocb
import (
"encoding/json"
gocbcore "github.com/couchbase/gocbcore/v8"
)
func serializeWrappedError(err error) string {
errBytes, serErr := json.Marshal(err)
if serErr != nil {
logErrorf("failed to serialize error to json: %s", serErr.Error())
}
return string(errBytes)
}
func maybeEnhanceCoreErr(err error) error {
if kvErr, ok := err.(gocbcore.KeyValueError); ok {
return KeyValueError{
InnerError: kvErr.InnerError,
StatusCode: kvErr.StatusCode,
BucketName: kvErr.BucketName,
ScopeName: kvErr.ScopeName,
CollectionName: kvErr.CollectionName,
CollectionID: kvErr.CollectionID,
ErrorName: kvErr.ErrorName,
ErrorDescription: kvErr.ErrorDescription,
Opaque: kvErr.Opaque,
Context: kvErr.Context,
Ref: kvErr.Ref,
RetryReasons: translateCoreRetryReasons(kvErr.RetryReasons),
RetryAttempts: kvErr.RetryAttempts,
}
}
if viewErr, ok := err.(gocbcore.ViewError); ok {
return ViewError{
InnerError: viewErr.InnerError,
DesignDocumentName: viewErr.DesignDocumentName,
ViewName: viewErr.ViewName,
Errors: translateCoreViewErrorDesc(viewErr.Errors),
Endpoint: viewErr.Endpoint,
RetryReasons: translateCoreRetryReasons(viewErr.RetryReasons),
RetryAttempts: viewErr.RetryAttempts,
}
}
if queryErr, ok := err.(gocbcore.N1QLError); ok {
return QueryError{
InnerError: queryErr.InnerError,
Statement: queryErr.Statement,
ClientContextID: queryErr.ClientContextID,
Errors: translateCoreQueryErrorDesc(queryErr.Errors),
Endpoint: queryErr.Endpoint,
RetryReasons: translateCoreRetryReasons(queryErr.RetryReasons),
RetryAttempts: queryErr.RetryAttempts,
}
}
if analyticsErr, ok := err.(gocbcore.AnalyticsError); ok {
return AnalyticsError{
InnerError: analyticsErr.InnerError,
Statement: analyticsErr.Statement,
ClientContextID: analyticsErr.ClientContextID,
Errors: translateCoreAnalyticsErrorDesc(analyticsErr.Errors),
Endpoint: analyticsErr.Endpoint,
RetryReasons: translateCoreRetryReasons(analyticsErr.RetryReasons),
RetryAttempts: analyticsErr.RetryAttempts,
}
}
if httpErr, ok := err.(gocbcore.HTTPError); ok {
return HTTPError{
InnerError: httpErr.InnerError,
UniqueID: httpErr.UniqueID,
Endpoint: httpErr.Endpoint,
RetryReasons: translateCoreRetryReasons(httpErr.RetryReasons),
RetryAttempts: httpErr.RetryAttempts,
}
}
return err
}
func maybeEnhanceKVErr(err error, bucketName, scopeName, collName, docKey string) error {
return maybeEnhanceCoreErr(err)
}
func maybeEnhanceCollKVErr(err error, bucket kvProvider, coll *Collection, docKey string) error {
return maybeEnhanceKVErr(err, coll.sb.BucketName, coll.Name(), coll.scopeName(), docKey)
}
func maybeEnhanceViewError(err error) error {
return maybeEnhanceCoreErr(err)
}
func maybeEnhanceQueryError(err error) error {
return maybeEnhanceCoreErr(err)
}
func maybeEnhanceAnalyticsError(err error) error {
return maybeEnhanceCoreErr(err)
}
func maybeEnhanceSearchError(err error) error {
return maybeEnhanceCoreErr(err)
}