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(x/staking,x/upgrade): replace fmt.Errorf without parameters with errors.New #21004

Merged
merged 1 commit into from
Jul 21, 2024

Conversation

yukionfire
Copy link
Contributor

@yukionfire yukionfire commented Jul 21, 2024

Similar to #20993

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling across various functions by standardizing error message creation, enhancing clarity and maintainability.
    • Adjusted error messages in functions related to validation and delegation to be simpler and more consistent.
  • Chores
    • Updated import statements for the errors package to support new error handling practices.

@yukionfire yukionfire requested a review from a team as a code owner July 21, 2024 07:07
Copy link
Contributor

coderabbitai bot commented Jul 21, 2024

Walkthrough

Walkthrough

The recent changes across multiple files primarily focus on improving error handling by replacing fmt.Errorf with errors.New. This adjustment enhances code readability and maintainability by standardizing how error messages are created, while preserving the existing logic and functionality throughout the affected functions. The modifications primarily target functions related to validation and state management in the staking and upgrade modules.

Changes

Files Change Summary
x/params/types/common_test.go, x/protocolpool/types/genesis.go, x/simulation/simulate.go, x/staking/keeper/delegation.go, x/staking/keeper/slash.go, x/staking/keeper/val_state_change.go, x/staking/keeper/validator.go, x/staking/types/params.go, x/upgrade/keeper/keeper.go, x/upgrade/keeper/migrations.go Replaced fmt.Errorf with errors.New for error messages in various functions to simplify error handling and improve consistency. No changes made to exported or public entity declarations.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant System
    User->>System: Invoke function with parameters
    System->>System: Validate inputs
    alt Input Valid
        System->>User: Return success response
    else Input Invalid
        System->>System: Generate error using errors.New
        System->>User: Return error message
    end
Loading

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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

CodeRabbit Configuration 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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 748352e and d02d993.

Files selected for processing (10)
  • x/params/types/common_test.go (1 hunks)
  • x/protocolpool/types/genesis.go (2 hunks)
  • x/simulation/simulate.go (2 hunks)
  • x/staking/keeper/delegation.go (1 hunks)
  • x/staking/keeper/slash.go (2 hunks)
  • x/staking/keeper/val_state_change.go (3 hunks)
  • x/staking/keeper/validator.go (1 hunks)
  • x/staking/types/params.go (1 hunks)
  • x/upgrade/keeper/keeper.go (1 hunks)
  • x/upgrade/keeper/migrations.go (2 hunks)
Files skipped from review due to trivial changes (4)
  • x/params/types/common_test.go
  • x/staking/keeper/delegation.go
  • x/staking/types/params.go
  • x/upgrade/keeper/keeper.go
Additional context used
Path-based instructions (6)
x/protocolpool/types/genesis.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/upgrade/keeper/migrations.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/simulation/simulate.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/staking/keeper/slash.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/staking/keeper/val_state_change.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/staking/keeper/validator.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

Learnings (1)
x/protocolpool/types/genesis.go (1)
Learnt from: likhita-809
PR: cosmos/cosmos-sdk#18471
File: x/protocolpool/keeper/genesis.go:12-51
Timestamp: 2023-11-22T12:32:39.368Z
Learning: - The user `likhita-809` has confirmed the changes suggested in the previous interaction.
- The file in question is `x/protocolpool/keeper/genesis.go` from a Cosmos SDK module.
- The changes involve optimizing the `InitGenesis` function by removing redundant code and ensuring proper handling of start times for budget proposals.
Additional comments not posted (11)
x/protocolpool/types/genesis.go (3)

43-43: LGTM!

The changes to replace fmt.Errorf with errors.New improve consistency in error handling.

Also applies to: 48-48, 51-51, 55-55, 59-59


66-66: LGTM!

The changes to replace fmt.Errorf with errors.New improve consistency in error handling.

Also applies to: 71-71, 74-74, 77-77


4-4: LGTM! Verify the usage of errorsmod.Wrap.

The import of errors and errorsmod is appropriate. Ensure that errorsmod.Wrap is used correctly in the codebase.

Also applies to: 6-6

Verification successful

The usage of errorsmod.Wrap is consistent and appropriate throughout the codebase.

  • The errorsmod.Wrap function is used correctly to provide additional context to errors, which aligns with best practices in error handling.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `errorsmod.Wrap` in the codebase.

# Test: Search for the usage of `errorsmod.Wrap`. Expect: Correct usage in the codebase.
rg --type go -A 5 $'errorsmod.Wrap'

Length of output: 198273

x/upgrade/keeper/migrations.go (1)

6-6: LGTM!

The changes to replace fmt.Errorf with errors.New improve consistency in error handling.

Also applies to: 67-67

x/simulation/simulate.go (1)

7-7: LGTM!

The changes to replace fmt.Errorf with errors.New improve consistency in error handling.

Also applies to: 117-117

x/staking/keeper/slash.go (3)

193-193: Ensure error message clarity.

The error message "invalid validator status" is now static. Ensure that this change does not remove any critical context that was previously provided by fmt.Errorf.


418-418: Ensure error message clarity.

The error message "unknown validator status" is now static. Ensure that this change does not remove any critical context that was previously provided by fmt.Errorf.


Line range hint 545-545: Ensure error message clarity.

The error message "unexpected validator in unbonding queue; status was not unbonding" is now static. Ensure that this change does not remove any critical context that was previously provided by fmt.Errorf.

x/staking/keeper/val_state_change.go (2)

176-176: Ensure error message clarity.

The error message "should never retrieve a jailed validator from the power store" is now static. Ensure that this change does not remove any critical context that was previously provided by fmt.Errorf.


202-202: Ensure error message clarity.

The error message "unexpected validator status" is now static. Ensure that this change does not remove any critical context that was previously provided by fmt.Errorf.

x/staking/keeper/validator.go (1)

545-545: Ensure error message clarity.

The error message "unexpected validator in unbonding queue; status was not unbonding" is now static. Ensure that this change does not remove any critical context that was previously provided by fmt.Errorf.

@sontrinh16 sontrinh16 added this pull request to the merge queue Jul 21, 2024
Merged via the queue into cosmos:main with commit e22890b Jul 21, 2024
72 of 73 checks passed
alpe added a commit that referenced this pull request Jul 23, 2024
* main: (48 commits)
  build(deps): add missing replaces and remove unnecessary ones (#21033)
  build(deps): Bump bufbuild/buf-setup-action from 1.34.0 to 1.35.0 (#21028)
  chore: fix some comments for struct field (#21027)
  chore(x): replace `fmt.Errorf` without parameters with `errors.New` (#21032)
  chore: fix errors reported by running `make lint` (#21015)
  ci: skip spelling check in go.mod/go.sum (#21021)
  chore(all)!: use gogoproto/any instead of codec/types/any (#21013)
  chore(server/v2/cometbft): ensure consistent dash-case in app.toml (#21018)
  docs(server): wrong function comments (#21017)
  refactor(storev2): update snapshot manager and migration manager tests (#20441)
  feat(server/v2/cometbft): config (#20989)
  refactor: set `help` as default target of Makefile (#21011)
  fix(simapp): duplicated import (#21014)
  chore(docs): fix functions and struct comments (#21010)
  fix(simapp/v2): panic with testnet init-files command (#21012)
  fix: make help won't work (#21005)
  fix: NewIntegrationApp does not write default genesis to state (#21006)
  chore(x/staking,x/upgrade): replace `fmt.Errorf` without parameters with `errors.New` (#21004)
  chore: prepare depinject 1.0.0 (#21001)
  docs: Fix typos in RFC Creation Process (#20998)
  ...
@yukionfire yukionfire deleted the chore/errors-fmt-x branch September 9, 2024 05:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants