-
Notifications
You must be signed in to change notification settings - Fork 77
/
errors.go
101 lines (81 loc) · 3.65 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
package ydb
import (
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb"
grpcCodes "google.golang.org/grpc/codes"
ratelimiterErrors "github.com/ydb-platform/ydb-go-sdk/v3/internal/ratelimiter/errors"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
"github.com/ydb-platform/ydb-go-sdk/v3/ratelimiter"
)
// IterateByIssues helps to iterate over internal issues of operation error.
func IterateByIssues(err error, it func(message string, code Ydb.StatusIds_StatusCode, severity uint32)) {
xerrors.IterateByIssues(err, it)
}
// IsTimeoutError checks whether given err is a some timeout error (context, transport or operation).
func IsTimeoutError(err error) bool {
return xerrors.IsTimeoutError(err)
}
// IsTransportError checks whether given err is a transport (grpc) error.
func IsTransportError(err error, codes ...grpcCodes.Code) bool {
return xerrors.IsTransportError(err, codes...)
}
// Error is an interface of error which reports about error code and error name.
type Error interface {
error
// Code reports the error code
Code() int32
// Name reports the short name of error
Name() string
}
// TransportError checks when given error is a transport error and returns description of transport error.
func TransportError(err error) Error {
return xerrors.TransportError(err)
}
// IsYdbError reports when given error is and ydb error (transport, operation or internal driver error)
func IsYdbError(err error) bool {
return xerrors.IsYdb(err)
}
// IsOperationError reports whether any error is an operation error with one of passed codes.
// If codes not defined IsOperationError returns true on error is an operation error.
func IsOperationError(err error, codes ...Ydb.StatusIds_StatusCode) bool {
return xerrors.IsOperationError(err, codes...)
}
// OperationError returns operation error description.
// If given err is not an operation error - returns nil.
func OperationError(err error) Error {
return xerrors.OperationError(err)
}
// IsOperationErrorOverloaded checks whether given err is an operation error with code Overloaded
func IsOperationErrorOverloaded(err error) bool {
return IsOperationError(err, Ydb.StatusIds_OVERLOADED)
}
// IsOperationErrorUnavailable checks whether given err is an operation error with code Unavailable
func IsOperationErrorUnavailable(err error) bool {
return IsOperationError(err, Ydb.StatusIds_UNAVAILABLE)
}
// IsOperationErrorAlreadyExistsError checks whether given err is an operation error with code AlreadyExistsError
func IsOperationErrorAlreadyExistsError(err error) bool {
return IsOperationError(err, Ydb.StatusIds_ALREADY_EXISTS)
}
// IsOperationErrorNotFoundError checks whether given err is an operation error with code NotFoundError
func IsOperationErrorNotFoundError(err error) bool {
return IsOperationError(err, Ydb.StatusIds_NOT_FOUND)
}
// IsOperationErrorSchemeError checks whether given err is an operation error with code SchemeError
func IsOperationErrorSchemeError(err error) bool {
return IsOperationError(err, Ydb.StatusIds_SCHEME_ERROR)
}
// IsOperationErrorTransactionLocksInvalidated checks does err a TLI issue
//
//nolint:nonamedreturns
func IsOperationErrorTransactionLocksInvalidated(err error) (isTLI bool) {
return xerrors.IsOperationErrorTransactionLocksInvalidated(err)
}
// IsRatelimiterAcquireError checks whether given err is an ratelimiter acquire error
func IsRatelimiterAcquireError(err error) bool {
return ratelimiterErrors.IsAcquireError(err)
}
// ToRatelimiterAcquireError casts given err to ratelimiter.AcquireError.
// If given err is not ratelimiter acquire error - returns nil
func ToRatelimiterAcquireError(err error) ratelimiter.AcquireError {
return ratelimiterErrors.ToAcquireError(err)
}