Skip to content

Commit f9c6f1f

Browse files
authored
Merge pull request #130 from ydb-platform/replace-strings-contains-error-message
Replaced in table/types/compare_test.go checking error by error messa…
2 parents 8ffb7d7 + 1d4adaa commit f9c6f1f

File tree

5 files changed

+15
-9
lines changed

5 files changed

+15
-9
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 3.11.3
2+
* Replaced in `table/types/compare_test.go` checking error by error message to checking with `errors.Is()`
3+
14
## 3.11.2
25
* Wrapped internal errors in retry operations
36

internal/table/retry.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,13 @@ func retryBackoff(
278278
panic("both of session and error are nil")
279279
}
280280
if err != nil {
281-
return errors.Errorf(0, "get session from pool failed: %w", ctx.Err())
281+
return errors.Errorf(0, "get session from pool failed: %w", err)
282282
}
283283
}
284284

285285
err = op(ctx, s)
286286
if err != nil {
287-
err = errors.Errorf(0, "retry operation failed: %w", ctx.Err())
287+
err = errors.Errorf(0, "retry operation failed: %w", err)
288288
}
289289

290290
if s.isClosing() {

retry/retry.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func Retry(ctx context.Context, op retryOperation, opts ...retryOption) (err err
122122
attempts++
123123
select {
124124
case <-ctx.Done():
125-
return ctx.Err()
125+
return errors.Errorf(0, "context done: %w", ctx.Err())
126126

127127
default:
128128
err = op(ctx)

table/types/compare_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package types
22

33
import (
4-
"strings"
54
"testing"
65

6+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/errors"
77
"github.com/ydb-platform/ydb-go-sdk/v3/testutil"
88
)
99

@@ -303,8 +303,8 @@ func TestIncompatiblePrimitives(t *testing.T) {
303303
if err == nil {
304304
t.Errorf("Error expected")
305305
}
306-
if !strings.Contains(err.Error(), "not comparable:") {
307-
t.Errorf("Unexpected error message: %s", err.Error())
306+
if !errors.Is(err, testutil.ErrNotComparable) {
307+
t.Errorf("Unexpected error: %v", err)
308308
}
309309
}
310310

@@ -314,8 +314,8 @@ func TestIncompatibleTuples(t *testing.T) {
314314
_, err := Compare(l, r)
315315
if err == nil {
316316
t.Error("Error expected")
317-
} else if !strings.Contains(err.Error(), "not comparable:") {
318-
t.Errorf("Unexpected error message: %s", err.Error())
317+
} else if !errors.Is(err, testutil.ErrNotComparable) {
318+
t.Errorf("Unexpected error: %v", err)
319319
}
320320
}
321321

testutil/compare.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package testutil
22

33
import (
44
"bytes"
5+
"fmt"
56
"math/big"
67
"strings"
78

@@ -11,6 +12,8 @@ import (
1112
"github.com/ydb-platform/ydb-go-sdk/v3/internal/value"
1213
)
1314

15+
var ErrNotComparable = fmt.Errorf("not comparable")
16+
1417
// Compare compares its operands.
1518
// It returns -1, 0, 1 if l < r, l == r, l > r. Returns error if types are not comparable.
1619
// Comparable types are all integer types, UUID, DyNumber, Float, Double, String, UTF8,
@@ -76,7 +79,7 @@ func expandTuple(v *Ydb.TypedValue) []*Ydb.TypedValue {
7679
}
7780

7881
func notComparableError(l interface{}, r interface{}) error {
79-
return errors.Errorf(1, "not comparable: %v and %v", l, r)
82+
return errors.Errorf(1, "%w: %v and %v", ErrNotComparable, l, r)
8083
}
8184

8285
func comparePrimitives(t Ydb.Type_PrimitiveTypeId, l *Ydb.Value, r *Ydb.Value) (int, error) {

0 commit comments

Comments
 (0)