Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wrappedError.Is #8355

Merged
merged 7 commits into from
Jan 18, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions types/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,11 @@ func (e *wrappedError) Cause() error {

// Is reports whether any error in e's chain matches a target.
func (e *wrappedError) Is(target error) bool {
if target == nil {
return e == target
if e == target {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now what happens when target == nil?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now - you mean with this update? If e is also nil it will return true, otherwise it will recurse and check.

In master this test fails:

require.True(errw.Is(errw), "should match itself") 

But this passes:

require.True(stdlib.Is(errs, errs)) 

return true
}

w := e.Cause()

for {
if w == target {
return true
Expand Down
15 changes: 11 additions & 4 deletions types/errors/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,24 @@ func (s *errorsTestSuite) TestWrapEmpty() {
}

func (s *errorsTestSuite) TestWrappedIs() {
require := s.Require()
err := Wrap(ErrTxTooLarge, "context")
s.Require().True(stdlib.Is(err, ErrTxTooLarge))
require.True(stdlib.Is(err, ErrTxTooLarge))

err = Wrap(err, "more context")
s.Require().True(stdlib.Is(err, ErrTxTooLarge))
require.True(stdlib.Is(err, ErrTxTooLarge))

err = Wrap(err, "even more context")
s.Require().True(stdlib.Is(err, ErrTxTooLarge))
require.True(stdlib.Is(err, ErrTxTooLarge))

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() {
Expand Down