github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/errors.go (about) 1 package ydb 2 3 import ( 4 "github.com/ydb-platform/ydb-go-genproto/protos/Ydb" 5 grpcCodes "google.golang.org/grpc/codes" 6 7 ratelimiterErrors "github.com/ydb-platform/ydb-go-sdk/v3/internal/ratelimiter/errors" 8 "github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors" 9 "github.com/ydb-platform/ydb-go-sdk/v3/ratelimiter" 10 ) 11 12 // IterateByIssues helps to iterate over internal issues of operation error. 13 func IterateByIssues(err error, it func(message string, code Ydb.StatusIds_StatusCode, severity uint32)) { 14 xerrors.IterateByIssues(err, it) 15 } 16 17 // IsTimeoutError checks whether given err is a some timeout error (context, transport or operation). 18 func IsTimeoutError(err error) bool { 19 return xerrors.IsTimeoutError(err) 20 } 21 22 // IsTransportError checks whether given err is a transport (grpc) error. 23 func IsTransportError(err error, codes ...grpcCodes.Code) bool { 24 return xerrors.IsTransportError(err, codes...) 25 } 26 27 // Error is an interface of error which reports about error code and error name. 28 type Error interface { 29 error 30 31 // Code reports the error code 32 Code() int32 33 34 // Name reports the short name of error 35 Name() string 36 } 37 38 // TransportError checks when given error is a transport error and returns description of transport error. 39 func TransportError(err error) Error { 40 return xerrors.TransportError(err) 41 } 42 43 // IsYdbError reports when given error is and ydb error (transport, operation or internal driver error) 44 func IsYdbError(err error) bool { 45 return xerrors.IsYdb(err) 46 } 47 48 // IsOperationError reports whether any error is an operation error with one of passed codes. 49 // If codes not defined IsOperationError returns true on error is an operation error. 50 func IsOperationError(err error, codes ...Ydb.StatusIds_StatusCode) bool { 51 return xerrors.IsOperationError(err, codes...) 52 } 53 54 // OperationError returns operation error description. 55 // If given err is not an operation error - returns nil. 56 func OperationError(err error) Error { 57 return xerrors.OperationError(err) 58 } 59 60 // IsOperationErrorOverloaded checks whether given err is an operation error with code Overloaded 61 func IsOperationErrorOverloaded(err error) bool { 62 return IsOperationError(err, Ydb.StatusIds_OVERLOADED) 63 } 64 65 // IsOperationErrorUnavailable checks whether given err is an operation error with code Unavailable 66 func IsOperationErrorUnavailable(err error) bool { 67 return IsOperationError(err, Ydb.StatusIds_UNAVAILABLE) 68 } 69 70 // IsOperationErrorAlreadyExistsError checks whether given err is an operation error with code AlreadyExistsError 71 func IsOperationErrorAlreadyExistsError(err error) bool { 72 return IsOperationError(err, Ydb.StatusIds_ALREADY_EXISTS) 73 } 74 75 // IsOperationErrorNotFoundError checks whether given err is an operation error with code NotFoundError 76 func IsOperationErrorNotFoundError(err error) bool { 77 return IsOperationError(err, Ydb.StatusIds_NOT_FOUND) 78 } 79 80 // IsOperationErrorSchemeError checks whether given err is an operation error with code SchemeError 81 func IsOperationErrorSchemeError(err error) bool { 82 return IsOperationError(err, Ydb.StatusIds_SCHEME_ERROR) 83 } 84 85 // IsOperationErrorTransactionLocksInvalidated checks does err a TLI issue 86 // 87 //nolint:nonamedreturns 88 func IsOperationErrorTransactionLocksInvalidated(err error) (isTLI bool) { 89 return xerrors.IsOperationErrorTransactionLocksInvalidated(err) 90 } 91 92 // IsRatelimiterAcquireError checks whether given err is an ratelimiter acquire error 93 func IsRatelimiterAcquireError(err error) bool { 94 return ratelimiterErrors.IsAcquireError(err) 95 } 96 97 // ToRatelimiterAcquireError casts given err to ratelimiter.AcquireError. 98 // If given err is not ratelimiter acquire error - returns nil 99 func ToRatelimiterAcquireError(err error) ratelimiter.AcquireError { 100 return ratelimiterErrors.ToAcquireError(err) 101 }