Skip to content

Commit

Permalink
Use errors instead xerrors
Browse files Browse the repository at this point in the history
  • Loading branch information
khasanovbi committed Feb 12, 2021
1 parent e47de69 commit 382c742
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 12 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module github.com/khasanovbi/banksdb/v2
require (
github.com/armon/go-radix v1.0.0
github.com/stretchr/testify v1.3.0
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7
gopkg.in/src-d/go-billy.v4 v4.3.2
gopkg.in/src-d/go-git.v4 v4.13.1
)
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190729092621-ff9f1409240a h1:mEQZbbaBjWyLNy0tmZmgEuQAR8XOQ3hL8GYi3J/NG64=
golang.org/x/tools v0.0.0-20190729092621-ff9f1409240a/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/src-d/go-billy.v4 v4.3.2 h1:0SQA1pRztfTFx2miS8sA97XvooFeNOmvUenF4o0EcVg=
Expand Down
6 changes: 3 additions & 3 deletions paymentsystem/payment_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package paymentsystem

import (
"errors"
"fmt"
"strconv"

"github.com/armon/go-radix"
"golang.org/x/xerrors"
)

// PaymentSystem represent system used to settle financial transactions.
Expand Down Expand Up @@ -92,7 +92,7 @@ func (r *radixDB) InitFromMap(rawPaymentSystems map[PaymentSystem][]paymentSyste
for _, prefixRange := range paymentSystemParam.prefixRanges {
rangePrefixes, err := splitPrefixRange(prefixRange)
if err != nil {
return xerrors.Errorf("prefix range split error: %w", err)
return fmt.Errorf("prefix range split error: %w", err)
}

prefixes = append(prefixes, rangePrefixes...)
Expand All @@ -105,7 +105,7 @@ func (r *radixDB) InitFromMap(rawPaymentSystems map[PaymentSystem][]paymentSyste
if isUpdated {
oldPaymentSystem := oldValue.(*radixValue).paymentSystem

return xerrors.Errorf(
return fmt.Errorf(
"prefix=%d, old=%s, new=%s: %w",
prefix,
oldPaymentSystem,
Expand Down
4 changes: 2 additions & 2 deletions paymentsystem/payment_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
package paymentsystem

import (
"errors"
"testing"

"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"golang.org/x/xerrors"
)

func TestFindPaymentSystem(t *testing.T) {
Expand Down Expand Up @@ -88,7 +88,7 @@ func (suite *RadixDBTestSuite) TestInitErrorAtSamePrefix() {
{prefixes: []int{1}, lengthChecker: &exactLengthChecker{Exact: 5}},
},
})
suite.Require().True(xerrors.Is(err, errNonUniquePrefix))
suite.Require().True(errors.Is(err, errNonUniquePrefix))
}

func TestRadixDBTestSuite(t *testing.T) {
Expand Down
7 changes: 3 additions & 4 deletions paymentsystem/prefix_range_splitter.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package paymentsystem

import (
"fmt"
"math"
"strconv"
"strings"

"golang.org/x/xerrors"
)

func findCommonPrefixLength(first string, second string) int {
Expand Down Expand Up @@ -99,7 +98,7 @@ func splitPrefixRange(prefixRange prefixRange) ([]int, error) {
toStr := strconv.Itoa(prefixRange.to)

if len(fromStr) != len(toStr) {
return nil, xerrors.Errorf("different prefix range lengths, from='%s', to='%s'", fromStr, toStr)
return nil, fmt.Errorf("different prefix range lengths, from='%s', to='%s'", fromStr, toStr)
}

strPrefixes := splitPrefixRangeStr(fromStr, toStr)
Expand All @@ -110,7 +109,7 @@ func splitPrefixRange(prefixRange prefixRange) ([]int, error) {
prefix, err := strconv.Atoi(strPrefix)
// Shouldn't be never not nil.
if err != nil {
return nil, xerrors.Errorf("prefix to int convert error: %w", err)
return nil, fmt.Errorf("prefix to int convert error: %w", err)
}

result = append(result, prefix)
Expand Down

0 comments on commit 382c742

Please sign in to comment.