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

Refactor UpgradeError to use bullt in errors functions #5704

Merged
merged 5 commits into from
Jan 24, 2024

Conversation

chatton
Copy link
Contributor

@chatton chatton commented Jan 24, 2024

Description

This PR does a refactor to utilize the errors.Is and errors.Unwrap functions.

@DimitrisJim pointed out we were using the Unrwap and Cause incorrectly. The implementations have been updated to reflect their intended use case.


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against the correct branch (see CONTRIBUTING.md).
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards and Go style guide.
  • Wrote unit and integration tests.
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/).
  • Added relevant godoc comments.
  • Provide a commit message to be used for the changelog entry in the PR description for review.
  • Re-reviewed Files changed in the Github PR explorer.
  • Review Codecov Report in the comment section below once CI passes.

@chatton chatton added the channel-upgradability Channel upgradability feature label Jan 24, 2024
return errors.Is(u.err, err)
// Is returns true if the of the provided error is an upgrade error.
func (*UpgradeError) Is(err error) bool {
_, ok := err.(*UpgradeError)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is the simplest approach, by implementing it this way, when we call errors.Is with an UpgradeError as an argument, it will handle the traversal of the error stack and eventually hit this.

Copy link
Contributor

Choose a reason for hiding this comment

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

yes! This is also what stdlib suggests https://pkg.go.dev/errors#Is

func (u *UpgradeError) Unwrap() error {
return u.err
Copy link
Contributor Author

Choose a reason for hiding this comment

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

when we call errors.Is, it will call Unwrap to traverse the stack.

Copy link
Contributor

@damiannolan damiannolan left a comment

Choose a reason for hiding this comment

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

Looks much cleaner! Nice 👍🏻

Copy link
Contributor

@DimitrisJim DimitrisJim left a comment

Choose a reason for hiding this comment

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

looks way better! thanks for looking into the clean up!

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (87dc82e) 81.25% compared to head (1bf4c07) 81.24%.
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #5704      +/-   ##
==========================================
- Coverage   81.25%   81.24%   -0.01%     
==========================================
  Files         199      199              
  Lines       15230    15224       -6     
==========================================
- Hits        12375    12369       -6     
  Misses       2389     2389              
  Partials      466      466              
Files Coverage Δ
modules/core/04-channel/types/upgrade.go 100.00% <100.00%> (ø)

Copy link
Contributor

@colin-axner colin-axner left a comment

Choose a reason for hiding this comment

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

Excellent! Thank you @chatton looking into this! The changes look super clean to me :)

@chatton chatton enabled auto-merge (squash) January 24, 2024 15:44
@chatton chatton merged commit 97ea045 into main Jan 24, 2024
60 of 62 checks passed
@chatton chatton deleted the cian/refactor-upgrade-error branch January 24, 2024 15:49
mergify bot pushed a commit that referenced this pull request Jan 24, 2024
DimitrisJim pushed a commit that referenced this pull request Jan 24, 2024
…#5715)

(cherry picked from commit 97ea045)

Co-authored-by: Cian Hatton <cian@interchain.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
channel-upgradability Channel upgradability feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants