Skip to content

Commit c8cf840

Browse files
committed
* Refactored errors wrapping (stackedError are not ydb error now, checking errors.IsYdb(err) with errors.As now)
1 parent af6b9fb commit c8cf840

28 files changed

+278
-207
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
* Refactored `cluster.Cluster` and `balancer.Balancer` interfaces (removed `Update` method)
22
* Replaced `cluster.Update` with `cluster.Remove` and `cluster.Insert` calls
33
* Fixed bug with unexpected changing of local datacenter flag in endpoint
4+
* Refactored errors wrapping (stackedError are not ydb error now, checking `errors.IsYdb(err)` with `errors.As` now)
45

56
## v3.16.9
67
* Refactored internal operation and transport errors

internal/cluster/cluster.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ const (
2424

2525
var (
2626
// ErrClusterClosed returned when requested on a closed cluster.
27-
ErrClusterClosed = fmt.Errorf("cluster closed")
27+
ErrClusterClosed = errors.New(fmt.Errorf("cluster closed"))
2828

2929
// ErrClusterEmpty returned when no connections left in cluster.
30-
ErrClusterEmpty = fmt.Errorf("cluster empty")
30+
ErrClusterEmpty = errors.New(fmt.Errorf("cluster empty"))
3131
)
3232

3333
type cluster struct {

internal/conn/conn.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import (
2020

2121
var (
2222
// errOperationNotReady specified error when operation is not ready
23-
errOperationNotReady = fmt.Errorf("operation is not ready yet")
23+
errOperationNotReady = errors.New(fmt.Errorf("operation is not ready yet"))
2424
// errClosedConnection specified error when connection are closed early
25-
errClosedConnection = fmt.Errorf("connection closed early")
25+
errClosedConnection = errors.New(fmt.Errorf("connection closed early"))
2626
)
2727

2828
type Conn interface {
@@ -374,7 +374,7 @@ func (c *conn) Invoke(
374374

375375
case o.GetOperation().GetStatus() != Ydb.StatusIds_SUCCESS:
376376
return errors.WithStackTrace(
377-
errors.NewOpError(
377+
errors.Operation(
378378
errors.FromOperation(
379379
o.GetOperation(),
380380
),

internal/conn/grpc_client_stream.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func (s *grpcClientStream) RecvMsg(m interface{}) (err error) {
8888
if operation, ok := m.(wrap.StreamOperationResponse); ok {
8989
if s := operation.GetStatus(); s != Ydb.StatusIds_SUCCESS {
9090
return errors.WithStackTrace(
91-
errors.NewOpError(
91+
errors.Operation(
9292
errors.FromOperation(
9393
operation,
9494
),

internal/credentials/credentials.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
// errNoCredentials may be returned by Credentials implementations to
1111
// make driver act as if there are no Credentials at all. That is, driver will
1212
// not send any token meta information during request.
13-
var errNoCredentials = fmt.Errorf("ydb: credentials: no credentials")
13+
var errNoCredentials = errors.New(fmt.Errorf("ydb: credentials: no credentials"))
1414

1515
// Credentials is an interface that contains options used to authorize a
1616
// client.

internal/decimal/errors.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package decimal
22

3-
import "fmt"
3+
import (
4+
"fmt"
45

5-
var ErrSyntax = fmt.Errorf("invalid syntax")
6+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/errors"
7+
)
8+
9+
var errSyntax = errors.New(fmt.Errorf("invalid syntax"))
610

711
type ParseError struct {
812
Err error
@@ -21,7 +25,7 @@ func (p *ParseError) Unwrap() error {
2125

2226
func syntaxError(s string) *ParseError {
2327
return &ParseError{
24-
Err: ErrSyntax,
28+
Err: errSyntax,
2529
Input: s,
2630
}
2731
}

internal/dsn/dsn.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ var (
2121
"grpcs": true,
2222
"grpc": false,
2323
}
24-
errSchemeNotValid = fmt.Errorf("schema not valid")
25-
errParserExists = fmt.Errorf("already exists parser. newest parser replaced old. param")
24+
errSchemeNotValid = errors.New(fmt.Errorf("schema not valid"))
25+
errParserExists = errors.New(fmt.Errorf("already exists parser. newest parser replaced old. param"))
2626
)
2727

2828
type Parser func(value string) ([]config.Option, error)

internal/errors/check.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ func Check(err error) (
99
) {
1010
var te *transportError
1111
var oe *operationError
12-
var re *RetryableError
12+
var re *retryableError
1313
switch {
1414
case As(err, &te):
1515
return int64(te.code),
@@ -24,8 +24,8 @@ func Check(err error) (
2424
case As(err, &re):
2525
return -1,
2626
OperationNotFinished,
27-
re.BackoffType,
28-
re.MustDeleteSession
27+
re.backoffType,
28+
re.mustDeleteSession
2929
default:
3030
return -1,
3131
OperationFinished, // it's finished, not need any retry attempts

internal/errors/errors.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package errors
33
import (
44
"context"
55
"errors"
6-
"fmt"
76
"io"
87

98
grpcCodes "google.golang.org/grpc/codes"
@@ -82,9 +81,3 @@ func Is(err error, targets ...error) bool {
8281
}
8382
return false
8483
}
85-
86-
// New is a proxy to errors.New
87-
// This need to single import errors
88-
func New(text string) error {
89-
return WithStackTrace(fmt.Errorf("%w", errors.New(text)), WithSkipDepth(1))
90-
}

internal/errors/operation.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,23 @@ type operation interface {
3030
}
3131

3232
// WithIssues is an option for construct operation error with issues list
33-
// WithIssues must use as `NewOpError(WithIssues(issues))`
33+
// WithIssues must use as `Operation(WithIssues(issues))`
3434
func WithIssues(issues []*Ydb_Issue.IssueMessage) oeOpt {
3535
return func(oe *operationError) {
3636
oe.issues = issues
3737
}
3838
}
3939

4040
// WithStatusCode is an option for construct operation error with reason code
41-
// WithStatusCode must use as `NewOpError(WithStatusCode(reason))`
41+
// WithStatusCode must use as `Operation(WithStatusCode(reason))`
4242
func WithStatusCode(code Ydb.StatusIds_StatusCode) oeOpt {
4343
return func(oe *operationError) {
4444
oe.code = code
4545
}
4646
}
4747

4848
// FromOperation is an option for construct operation error from operation
49-
// FromOperation must use as `NewOpError(FromOperation(operation))`
49+
// FromOperation must use as `Operation(FromOperation(operation))`
5050
func FromOperation(operation operation) oeOpt {
5151
return func(oe *operationError) {
5252
oe.code = operation.GetStatus()
@@ -56,7 +56,7 @@ func FromOperation(operation operation) oeOpt {
5656

5757
type oeOpt func(ops *operationError)
5858

59-
func NewOpError(opts ...oeOpt) error {
59+
func Operation(opts ...oeOpt) error {
6060
oe := &operationError{
6161
code: Ydb.StatusIds_STATUS_CODE_UNSPECIFIED,
6262
}

0 commit comments

Comments
 (0)