fix: types/errors Wrap and Wrapf (#10674)
<!-- The default pull request template is for types feat, fix, or refactor. For other templates, add one of the following parameters to the url: - template=docs.md - template=other.md --> ## Description The `Error.Wrap` and `Error.Wrapf` functions in `types/errors` didn't work with `Is` and `IsOf` because they had non-pointer receivers. This adds a fix and tests that failed and now pass. --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [x] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
This commit is contained in:
parent
c41ac20c6c
commit
9566c99185
|
@ -165,7 +165,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||||
* [\#10466](https://github.com/cosmos/cosmos-sdk/issues/10466) Fixes error with simulation tests when genesis start time is randomly created after the year 2262
|
* [\#10466](https://github.com/cosmos/cosmos-sdk/issues/10466) Fixes error with simulation tests when genesis start time is randomly created after the year 2262
|
||||||
* [\#10394](https://github.com/cosmos/cosmos-sdk/issues/10394) Fixes issue related to grpc-gateway of account balance by
|
* [\#10394](https://github.com/cosmos/cosmos-sdk/issues/10394) Fixes issue related to grpc-gateway of account balance by
|
||||||
ibc-denom.
|
ibc-denom.
|
||||||
* [#10593](https://github.com/cosmos/cosmos-sdk/pull/10593) Update swagger-ui to v4.1.0 to fix xss vulnerability.
|
* [\#10593](https://github.com/cosmos/cosmos-sdk/pull/10593) Update swagger-ui to v4.1.0 to fix xss vulnerability.
|
||||||
|
* [\#10674](https://github.com/cosmos/cosmos-sdk/pull/10674) Fix issue with `Error.Wrap` and `Error.Wrapf` usage with `errors.Is`.
|
||||||
|
|
||||||
### State Machine Breaking
|
### State Machine Breaking
|
||||||
|
|
||||||
|
|
|
@ -266,11 +266,11 @@ func (e *Error) Is(err error) bool {
|
||||||
|
|
||||||
// Wrap extends this error with an additional information.
|
// Wrap extends this error with an additional information.
|
||||||
// It's a handy function to call Wrap with sdk errors.
|
// It's a handy function to call Wrap with sdk errors.
|
||||||
func (e Error) Wrap(desc string) error { return Wrap(e, desc) }
|
func (e *Error) Wrap(desc string) error { return Wrap(e, desc) }
|
||||||
|
|
||||||
// Wrapf extends this error with an additional information.
|
// Wrapf extends this error with an additional information.
|
||||||
// It's a handy function to call Wrapf with sdk errors.
|
// It's a handy function to call Wrapf with sdk errors.
|
||||||
func (e Error) Wrapf(desc string, args ...interface{}) error { return Wrapf(e, desc, args...) }
|
func (e *Error) Wrapf(desc string, args ...interface{}) error { return Wrapf(e, desc, args...) }
|
||||||
|
|
||||||
func isNilErr(err error) bool {
|
func isNilErr(err error) bool {
|
||||||
// Reflect usage is necessary to correctly compare with
|
// Reflect usage is necessary to correctly compare with
|
||||||
|
|
|
@ -200,6 +200,11 @@ func (s *errorsTestSuite) TestWrappedIs() {
|
||||||
|
|
||||||
errw := &wrappedError{"msg", errs}
|
errw := &wrappedError{"msg", errs}
|
||||||
require.True(errw.Is(errw), "should match itself")
|
require.True(errw.Is(errw), "should match itself")
|
||||||
|
|
||||||
|
require.True(stdlib.Is(ErrInsufficientFee.Wrap("wrapped"), ErrInsufficientFee))
|
||||||
|
require.True(IsOf(ErrInsufficientFee.Wrap("wrapped"), ErrInsufficientFee))
|
||||||
|
require.True(stdlib.Is(ErrInsufficientFee.Wrapf("wrapped"), ErrInsufficientFee))
|
||||||
|
require.True(IsOf(ErrInsufficientFee.Wrapf("wrapped"), ErrInsufficientFee))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *errorsTestSuite) TestWrappedIsMultiple() {
|
func (s *errorsTestSuite) TestWrappedIsMultiple() {
|
||||||
|
|
Loading…
Reference in New Issue