Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is a suggestion how to assert wrapped errors (see #334).
It covers two related but different use cases:
Instead of having separate matchers for wrapped errors, the existing
MatchError
matcher is extended to test forerrors.Is()
anderrors.As()
.Rationale:
I think it makes sense to really test against
errors.Is()
anderrors.As()
instead of "only" testing for wrapped errors as aWrapError
matcher would do sinceIs()
andAs()
can returntrue
although there are no wrapped errors at all.I also think that it makes sense to test
errors.Is()
within the existingMatchError
matcher instead of having an additional matcher which would be named likeBeError
since it would sound confusing to the user what the difference is betweenMatchError
andBeError
.(One possibility is to extract the test for
errors.As()
into a separate matcher which would be named something likeWrapOrBeAssignableToTypeOf
. However, this also doesn't sound very clear.)