Skip to content

Commit

Permalink
all: Fix improper use of errors.Wrap (#4926)
Browse files Browse the repository at this point in the history
* all: Fix improper use of errors.Wrap

`errors.Wrap` method returns nil if the first argument passed is also nil.
If `errors.Wrap` is copied from a condition like `if err != nil` to another
one which  also returns `errors.Wrap` but does not overwrite `err` before
the returned value will always be `nil`.

* Update services/horizon/internal/db2/history/claimable_balances.go

Co-authored-by: George <[email protected]>

---------

Co-authored-by: George <[email protected]>
Co-authored-by: Tsachi Herman <[email protected]>
  • Loading branch information
3 people authored Jun 27, 2023
1 parent 7aafb6d commit ff665ec
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (cbq ClaimableBalancesQuery) Cursor() (int64, string, error) {
}
r = parts[1]
if l < 0 {
return l, r, errors.Wrap(err, "Invalid cursor - first value should be higher than 0")
return l, r, errors.New("invalid cursor - first value should be higher than 0")
}
}

Expand Down
4 changes: 2 additions & 2 deletions services/horizon/internal/db2/history/orderbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (q *Q) GetOrderBookSummary(ctx context.Context, sellingAsset, buyingAsset x
// we don't expect there to be any inconsistency between levels and offers because
// this function should only be invoked in a repeatable read transaction
if len(levels) != len(offers) {
return result, errors.Wrap(err, "price levels length does not match summaries length")
return result, errors.New("price levels length does not match summaries length")
}
for i, level := range levels {
sum := offers[i]
Expand Down Expand Up @@ -151,7 +151,7 @@ func (q *Q) GetOrderBookSummary(ctx context.Context, sellingAsset, buyingAsset x
} else if sum.Type == "bid" {
result.Bids = append(result.Bids, entry)
} else {
return result, errors.Wrap(err, "invalid offer type")
return result, errors.New("invalid offer type")
}
}

Expand Down
2 changes: 1 addition & 1 deletion services/horizon/internal/db2/history/verify_lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (q *Q) TryStateVerificationLock(ctx context.Context) (bool, error) {
return false, errors.Wrap(err, "error acquiring advisory lock for state verification")
}
if len(acquired) != 1 {
return false, errors.Wrap(err, "invalid response from advisory lock")
return false, errors.New("invalid response from advisory lock")
}
return acquired[0], nil
}

0 comments on commit ff665ec

Please sign in to comment.