Skip to content

Conversation

@fabiante
Copy link
Contributor

@fabiante fabiante commented Sep 7, 2023

This PR fixes error handling for wrapped errors.

This bug was caused by wrong parameter order in the usage of errors.Is

The added test case shows a use case.

@richzw This changes the behaviour of the middleware: Now - errors which may deeply wrap other errors could match in the middleware where they previously didn't. I think this change fixes a bug but maybe you want the behaviour do not change? LMK.

This exposes a bug in the existing implementation.
Wrapped errors are not handled by the middleware.
The parameters used where in the wrong order.
@fabiante fabiante marked this pull request as ready for review September 7, 2023 15:02
@fabiante fabiante changed the title Fix error handling for wrapped errors Fix error handling of wrapped errors Sep 7, 2023
Copy link
Owner

@richzw richzw left a comment

Choose a reason for hiding this comment

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

Thank you very much for your PR. I think it could be better for if errors.Is(lastError.Err, e) || errors.Is(e, lastError.Err) { since the only the first parameter of errors.is was Unwrap .

This allows simpler unit tests of the matching logic and reduces complexity
of the original function.
These ensure the matching will stay the same for future changes
without the testing overhead of performing an http request.
This has been suggested in PR review.
It seems that all tests are fine without the second comparison.
@fabiante fabiante requested a review from richzw September 8, 2023 06:26
@fabiante
Copy link
Contributor Author

fabiante commented Sep 8, 2023

Thx for the feedback. I think it is useful to move the error matching into it's own function which allowed for far simpler unit testing.

After I applied you change, which I don't yet fully get, I wanted to test if we even need two comparisons. Have a look at the changes and tell me what you think. I think only one comparison is actually needed.

Tests are green.

Copy link
Owner

@richzw richzw left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you very much for your PR

@richzw richzw merged commit b7258d0 into richzw:master Sep 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants