fix: wrappedError.Is (#8355)
* fix: wrappedError.Is Is method should return true when used on 2 same errors. * Changelog update Co-authored-by: Alessio Treglia <alessio@tendermint.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
parent
d84ca99788
commit
e8d47bb93b
|
@ -42,8 +42,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
|
|
||||||
* (x/auth) [\#8287](https://github.com/cosmos/cosmos-sdk/pull/8287) Fix `tx sign --signature-only` to return correct sequence value in signature.
|
* (x/auth) [\#8287](https://github.com/cosmos/cosmos-sdk/pull/8287) Fix `tx sign --signature-only` to return correct sequence value in signature.
|
||||||
* (x/ibc) [\#8341](https://github.com/cosmos/cosmos-sdk/pull/8341) Fix query latest consensus state.
|
* (x/ibc) [\#8341](https://github.com/cosmos/cosmos-sdk/pull/8341) Fix query latest consensus state.
|
||||||
|
* (types/errors) [\#8355][https://github.com/cosmos/cosmos-sdk/pull/8355] Fix errorWrap `Is` method.
|
||||||
|
|
||||||
|
|
||||||
## [v0.40.0](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.40.0) - 2021-01-08
|
## [v0.40.0](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.40.0) - 2021-01-08
|
||||||
|
|
||||||
|
@ -201,7 +203,7 @@ sure you are aware of any relevant breaking changes.
|
||||||
* (x/slashing) [\#6212](https://github.com/cosmos/cosmos-sdk/pull/6212) Remove `Get*` prefixes from key construction functions
|
* (x/slashing) [\#6212](https://github.com/cosmos/cosmos-sdk/pull/6212) Remove `Get*` prefixes from key construction functions
|
||||||
* (server) [\#6079](https://github.com/cosmos/cosmos-sdk/pull/6079) Remove `UpgradeOldPrivValFile` (deprecated in Tendermint Core v0.28).
|
* (server) [\#6079](https://github.com/cosmos/cosmos-sdk/pull/6079) Remove `UpgradeOldPrivValFile` (deprecated in Tendermint Core v0.28).
|
||||||
* [\#5719](https://github.com/cosmos/cosmos-sdk/pull/5719) Bump Go requirement to 1.14+
|
* [\#5719](https://github.com/cosmos/cosmos-sdk/pull/5719) Bump Go requirement to 1.14+
|
||||||
|
|
||||||
|
|
||||||
### State Machine Breaking
|
### State Machine Breaking
|
||||||
|
|
||||||
|
|
|
@ -318,12 +318,11 @@ func (e *wrappedError) Cause() error {
|
||||||
|
|
||||||
// Is reports whether any error in e's chain matches a target.
|
// Is reports whether any error in e's chain matches a target.
|
||||||
func (e *wrappedError) Is(target error) bool {
|
func (e *wrappedError) Is(target error) bool {
|
||||||
if target == nil {
|
if e == target {
|
||||||
return e == target
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
w := e.Cause()
|
w := e.Cause()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
if w == target {
|
if w == target {
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -161,17 +161,24 @@ func (s *errorsTestSuite) TestWrapEmpty() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *errorsTestSuite) TestWrappedIs() {
|
func (s *errorsTestSuite) TestWrappedIs() {
|
||||||
|
require := s.Require()
|
||||||
err := Wrap(ErrTxTooLarge, "context")
|
err := Wrap(ErrTxTooLarge, "context")
|
||||||
s.Require().True(stdlib.Is(err, ErrTxTooLarge))
|
require.True(stdlib.Is(err, ErrTxTooLarge))
|
||||||
|
|
||||||
err = Wrap(err, "more context")
|
err = Wrap(err, "more context")
|
||||||
s.Require().True(stdlib.Is(err, ErrTxTooLarge))
|
require.True(stdlib.Is(err, ErrTxTooLarge))
|
||||||
|
|
||||||
err = Wrap(err, "even more context")
|
err = Wrap(err, "even more context")
|
||||||
s.Require().True(stdlib.Is(err, ErrTxTooLarge))
|
require.True(stdlib.Is(err, ErrTxTooLarge))
|
||||||
|
|
||||||
err = Wrap(ErrInsufficientFee, "...")
|
err = Wrap(ErrInsufficientFee, "...")
|
||||||
s.Require().False(stdlib.Is(err, ErrTxTooLarge))
|
require.False(stdlib.Is(err, ErrTxTooLarge))
|
||||||
|
|
||||||
|
errs := stdlib.New("other")
|
||||||
|
require.True(stdlib.Is(errs, errs))
|
||||||
|
|
||||||
|
errw := &wrappedError{"msg", errs}
|
||||||
|
require.True(errw.Is(errw), "should match itself")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *errorsTestSuite) TestWrappedIsMultiple() {
|
func (s *errorsTestSuite) TestWrappedIsMultiple() {
|
||||||
|
|
Loading…
Reference in New Issue