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

chore: address linter issues in 04-channel, 06-solomachines, 09-localhost #6130

Merged
merged 12 commits into from
Apr 12, 2024

Conversation

bznein
Copy link
Contributor

@bznein bznein commented Apr 9, 2024

Description

There are also a couple changes to 07-tenderming but I realized after that there are much more in that module so I'm going to do them separately.

ref: #6086


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/).
  • Added relevant godoc comments.
  • Provide a conventional commit message to follow the repository standards.
  • Include a descriptive changelog entry when appropriate. This may be left to the discretion of the PR reviewers. (e.g. chores should be omitted from changelog)
  • Re-reviewed Files changed in the GitHub PR explorer.
  • Review SonarCloud Report in the comment section below once CI passes.

Summary by CodeRabbit

  • Refactor
    • Enhanced error handling and type assertion checks across various modules to improve code robustness.
  • Tests
    • Updated tests to include checks for successful type assertions, ensuring more reliable test outcomes.

Copy link
Contributor

coderabbitai bot commented Apr 9, 2024

Walkthrough

The series of updates across various modules primarily focuses on enhancing type safety and error handling in the codebase. By incorporating checks for successful type assertions and improving error messages, these changes aim to make the code more robust and maintainable. This shift towards explicit error handling and type safety is a testament to the commitment to code quality and reliability.

Changes

Files Change Summary
.../04-channel/keeper/packet_test.go Modified timeoutHeight assignment with a boolean check for type assertion success.
.../04-channel/types/msgs_test.go, .../09-localhost/store.go Added import for fmt, modified type assertion checks, and error handling.
.../06-solomachine/light_client_module_test.go, .../solomachine_test.go, .../09-localhost/client_state_test.go Updated type assertion handling with ok variables for robustness.
.../06-solomachine/store.go, .../07-tendermint/store.go Enhanced error handling with explicit type assertions and error messages.
.../07-tendermint/update.go Replaced type assertion in UpdateState with a check for success, followed by a panic on failure.

🐰✨

In a land of code and binary streams,
A rabbit hopped, chasing robust dreams.
With checks and types, it mended seams,
Ensuring not a byte out of themes.
So here's to safety, no matter how extreme!
🌟🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

modules/light-clients/06-solomachine/store.go Fixed Show fixed Hide fixed
var clientState *ClientState
clientState, ok := clientStateI.(*ClientState)
if !ok {
panic(fmt.Errorf("cannot convert %T into %T", clientStateI, clientState))

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
modules/light-clients/07-tendermint/store.go Fixed Show fixed Hide fixed
height := header.GetHeight().(clienttypes.Height)
height, ok := header.GetHeight().(clienttypes.Height)
if !ok {
panic(fmt.Errorf("cannot convert %T to %T", header.GetHeight(), &clienttypes.Height{}))

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
modules/light-clients/09-localhost/store.go Fixed Show fixed Hide fixed
@bznein
Copy link
Contributor Author

bznein commented Apr 9, 2024

Interesting findings by CodeQL, thought I'm not sure what would be the best thing to do then :)

@DimitrisJim
Copy link
Contributor

Interesting findings by CodeQL, thought I'm not sure what would be the best thing to do then :)

these were applicable even before the change, seems it couldn't find them, though 🤔

@bznein
Copy link
Contributor Author

bznein commented Apr 10, 2024

Interesting findings by CodeQL, thought I'm not sure what would be the best thing to do then :)

these were applicable even before the change, seems it couldn't find them, though 🤔

My guess would be that CodeQL was enabled after this file was touched last time and it only runs on modified files? Absolutely not sure though :)

@bznein bznein requested a review from DimitrisJim April 10, 2024 10:58
@DimitrisJim
Copy link
Contributor

hm, probably. Either way, this seems safe to ignore, the panics were already a possibility before.

var clientState *ClientState
clientState, ok := clientStateI.(*ClientState)
if !ok {
panic(fmt.Errorf("cannot convert %T to %T", clientStateI, clientState))

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
var consensusState *ConsensusState
consensusState, ok := consensusStateI.(*ConsensusState)
if !ok {
panic(fmt.Errorf("cannot convert %T into %T", consensusStateI, consensusState))

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
var clientState *ClientState
clientState, ok := clientStateI.(*ClientState)
if !ok {
panic(fmt.Errorf("cannot convert %T into %T", clientStateI, clientState))

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
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.

🙏

Copy link
Contributor

@crodriguezvega crodriguezvega left a comment

Choose a reason for hiding this comment

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

🙏

var clientState *ClientState
clientState, ok := clientStateI.(*ClientState)
if !ok {
panic(fmt.Errorf("cannot convert %T to %T", clientStateI, clientState))
Copy link
Contributor

@crodriguezvega crodriguezvega Apr 10, 2024

Choose a reason for hiding this comment

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

I guess if we wanted to avoid the panic we could return nil, false, but that's stretching maybe a bit too much the semantics of the function signature...

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 agree that nil, false would probably hide the issue. The other way would be to change the signature to return an error, but it seems this would become a much broader PR

@crodriguezvega crodriguezvega merged commit eda92ef into cosmos:main Apr 12, 2024
75 checks passed
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.

3 participants