|
1 | 1 | package ydb |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Issue" |
| 4 | + "github.com/ydb-platform/ydb-go-genproto/protos/Ydb" |
| 5 | + grpcCodes "google.golang.org/grpc/codes" |
5 | 6 |
|
6 | 7 | "github.com/ydb-platform/ydb-go-sdk/v3/internal/errors" |
7 | 8 | ratelimiterErrors "github.com/ydb-platform/ydb-go-sdk/v3/internal/ratelimiter/errors" |
8 | 9 | "github.com/ydb-platform/ydb-go-sdk/v3/ratelimiter" |
9 | 10 | ) |
10 | 11 |
|
11 | | -func IterateByIssues(err error, it func(message string, code uint32, severity uint32)) { |
12 | | - var o *errors.OperationError |
13 | | - if !errors.As(err, &o) { |
14 | | - return |
15 | | - } |
16 | | - issues := o.Issues() |
17 | | - iterate(issues, it) |
18 | | -} |
19 | | - |
20 | | -func iterate(issues []*Ydb_Issue.IssueMessage, it func(message string, code uint32, severity uint32)) { |
21 | | - for _, issue := range issues { |
22 | | - it(issue.GetMessage(), issue.GetIssueCode(), issue.GetSeverity()) |
23 | | - iterate(issue.GetIssues(), it) |
24 | | - } |
| 12 | +func IterateByIssues(err error, it func(message string, code Ydb.StatusIds_StatusCode, severity uint32)) { |
| 13 | + errors.IterateByIssues(err, it) |
25 | 14 | } |
26 | 15 |
|
27 | 16 | func IsTimeoutError(err error) bool { |
28 | 17 | return errors.IsTimeoutError(err) |
29 | 18 | } |
30 | 19 |
|
31 | | -func IsTransportError(err error, codes ...int32) bool { |
32 | | - return errors.IsTransportError( |
33 | | - err, |
34 | | - func() (cc []errors.TransportErrorCode) { |
35 | | - for _, code := range codes { |
36 | | - cc = append(cc, errors.TransportErrorCode(code)) |
37 | | - } |
38 | | - return cc |
39 | | - }()..., |
40 | | - ) |
41 | | -} |
42 | | - |
43 | | -func IsTransportErrorCancelled(err error) bool { |
44 | | - return IsTransportError(err, int32(errors.TransportErrorCanceled)) |
| 20 | +func IsTransportError(err error, codes ...grpcCodes.Code) bool { |
| 21 | + return errors.IsTransportError(err, codes...) |
45 | 22 | } |
46 | 23 |
|
47 | | -func IsTransportErrorResourceExhausted(err error) bool { |
48 | | - return IsTransportError(err, int32(errors.TransportErrorResourceExhausted)) |
49 | | -} |
50 | | - |
51 | | -type Error interface { |
52 | | - error |
53 | | - |
54 | | - Code() int32 |
55 | | - Name() string |
56 | | -} |
| 24 | +type Error errors.Error |
57 | 25 |
|
58 | | -func TransportErrorDescription(err error) Error { |
59 | | - var t *errors.TransportError |
60 | | - if errors.As(err, &t) { |
61 | | - return t |
62 | | - } |
63 | | - return nil |
| 26 | +func TransportError(err error) Error { |
| 27 | + return errors.TransportError(err) |
64 | 28 | } |
65 | 29 |
|
66 | 30 | func IsYdbError(err error) bool { |
67 | | - return IsTransportError(err) || IsOperationError(err) |
| 31 | + return errors.IsYdb(err) |
68 | 32 | } |
69 | 33 |
|
70 | | -func IsOperationError(err error, codes ...int32) bool { |
71 | | - return errors.IsOpError( |
72 | | - err, |
73 | | - func() (cc []errors.StatusCode) { |
74 | | - for _, code := range codes { |
75 | | - cc = append(cc, errors.StatusCode(code)) |
76 | | - } |
77 | | - return cc |
78 | | - }()..., |
79 | | - ) |
| 34 | +func IsOperationError(err error, codes ...Ydb.StatusIds_StatusCode) bool { |
| 35 | + return errors.IsOperationError(err, codes...) |
80 | 36 | } |
81 | 37 |
|
82 | | -func OperationErrorDescription(err error) Error { |
83 | | - var o *errors.OperationError |
84 | | - if errors.As(err, &o) { |
85 | | - return o |
86 | | - } |
87 | | - return nil |
| 38 | +func OperationError(err error) Error { |
| 39 | + return errors.OperationError(err) |
88 | 40 | } |
89 | 41 |
|
90 | 42 | func IsOperationErrorOverloaded(err error) bool { |
91 | | - return IsOperationError(err, int32(errors.StatusOverloaded)) |
| 43 | + return IsOperationError(err, Ydb.StatusIds_OVERLOADED) |
92 | 44 | } |
93 | 45 |
|
94 | 46 | func IsOperationErrorUnavailable(err error) bool { |
95 | | - return IsOperationError(err, int32(errors.StatusUnavailable)) |
| 47 | + return IsOperationError(err, Ydb.StatusIds_UNAVAILABLE) |
96 | 48 | } |
97 | 49 |
|
98 | 50 | func IsOperationErrorAlreadyExistsError(err error) bool { |
99 | | - return IsOperationError(err, int32(errors.StatusAlreadyExists)) |
| 51 | + return IsOperationError(err, Ydb.StatusIds_ALREADY_EXISTS) |
100 | 52 | } |
101 | 53 |
|
102 | 54 | func IsOperationErrorNotFoundError(err error) bool { |
103 | | - return IsOperationError(err, int32(errors.StatusNotFound)) |
| 55 | + return IsOperationError(err, Ydb.StatusIds_NOT_FOUND) |
104 | 56 | } |
105 | 57 |
|
106 | 58 | func IsOperationErrorSchemeError(err error) bool { |
107 | | - return IsOperationError(err, int32(errors.StatusSchemeError)) |
| 59 | + return IsOperationError(err, Ydb.StatusIds_SCHEME_ERROR) |
108 | 60 | } |
109 | 61 |
|
110 | 62 | func IsRatelimiterAcquireError(err error) bool { |
|
0 commit comments