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: use errors.New to replace fmt.Errorf with no parameters #8873

Closed
wants to merge 2 commits into from

Conversation

ChengenH
Copy link

@ChengenH ChengenH commented Dec 8, 2024

No description provided.

@github-actions github-actions bot added C:CLI C:x/gamm Changes, features and bugs related to the gamm module. C:simulator Edits simulator or simulations labels Dec 8, 2024
Copy link
Contributor

coderabbitai bot commented Dec 8, 2024

Walkthrough

The pull request introduces significant updates to the CONTRIBUTING.md file, enhancing guidelines for contributions to the Osmosis chain development repository. It includes clarifications on contribution types, a detailed workflow for proposing changes, expanded testing guidelines, new instructions for local debugging and testing, a section on security considerations, and a description of the pre-release auditing process. Additionally, several files in the x/gamm package have been modified to improve error handling, primarily by replacing fmt.Errorf with errors.New for consistency across the codebase.

Changes

File Path Change Summary
CONTRIBUTING.md Added guidelines on contribution types, proposing changes workflow, testing, debugging, security, and pre-release auditing process.
x/gamm/client/cli/tx.go Updated error handling in functions to replace fmt.Errorf with errors.New. Minor documentation adjustments made.
x/gamm/keeper/migrate.go Introduced errors import and updated error handling in MigrateUnlockedPositionFromBalancerToConcentrated method.
x/gamm/keeper/pool.go Added errors import, updated panic messages to use errors.New, and modified error return behavior in GetCFMMPool.
x/gamm/pool-models/balancer/pool.go Replaced fmt.Errorf with errors.New for error handling in SetInitialPoolAssets and UpdatePoolAssetBalance methods.
x/gamm/pool-models/balancer/pool_asset.go Updated error handling in validateWeight method to use errors.New instead of fmt.Errorf. Adjusted imports accordingly.
x/gamm/simulation/sim_msgs.go Changed error handling in RandomCreateUniV2Msg and other functions to use errors.New. Maintained core logic.
x/gamm/types/gov.go Updated ValidateBasic methods in proposal types to use errors.New for error messages. Added errors import.

Possibly related PRs

Suggested labels

C:docs, C:x/gamm, A:no-changelog, V:state/compatible/backport

Suggested reviewers

  • mattverse
  • PaddyMc
  • czarcas7ic
  • AlpinYukseloglu
  • p0mvn
  • crnbarr93

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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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

🧹 Outside diff range and nitpick comments (1)
x/gamm/pool-models/balancer/pool.go (1)

Line range hint 1-1000: Consider using error constants for better maintainability.

While the error message changes are good, consider defining these common error messages as constants at the package level, similar to the existing constants in the file. This would improve maintainability and reusability.

const (
+   ErrZeroOrNegativeBalance = "can't add the zero or negative balance of token"
+   ErrDuplicatePoolAsset   = "same PoolAsset already exists"
+   ErrInvalidPoolBalance   = "can't set the pool's balance of a token to be zero or negative"
    // ... existing constants ...
)

// Then use these constants in the code:
-return errors.New("can't add the zero or negative balance of token")
+return errors.New(ErrZeroOrNegativeBalance)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1a181bf and 17e1dab.

📒 Files selected for processing (8)
  • CONTRIBUTING.md (1 hunks)
  • x/gamm/client/cli/tx.go (2 hunks)
  • x/gamm/keeper/migrate.go (2 hunks)
  • x/gamm/keeper/pool.go (2 hunks)
  • x/gamm/pool-models/balancer/pool.go (3 hunks)
  • x/gamm/pool-models/balancer/pool_asset.go (2 hunks)
  • x/gamm/simulation/sim_msgs.go (1 hunks)
  • x/gamm/types/gov.go (5 hunks)
🔇 Additional comments (12)
x/gamm/pool-models/balancer/pool_asset.go (1)

26-26: LGTM! Appropriate use of errors.New

The change from fmt.Errorf to errors.New is correct here since the error message is static with no parameters.

x/gamm/types/gov.go (2)

68-68: LGTM! Consistent error handling for empty records

Both instances correctly use errors.New for the static error message "empty proposal records".

Also applies to: 120-120


Line range hint 178-199: LGTM! Appropriate mix of error handling approaches

The changes correctly:

  1. Use errors.New for static messages (tick spacing, denom comparison, spread factor, pool ID)
  2. Retain fmt.Errorf where parameter formatting is needed (denom validation errors)
x/gamm/keeper/pool.go (1)

263-263: LGTM! Appropriate use of errors.New in panic message

The change from fmt.Errorf to errors.New is correct here since the panic message is static with no parameters.

x/gamm/keeper/migrate.go (1)

52-52: LGTM: Appropriate use of errors.New

The change from fmt.Errorf to errors.New is correct here as the error message is a static string with no parameters.

x/gamm/simulation/sim_msgs.go (1)

99-99: LGTM: Appropriate use of errors.New

The change from fmt.Errorf to errors.New is correct here as the error message is a static string with no parameters.

x/gamm/client/cli/tx.go (2)

530-530: LGTM: Appropriate use of errors.New

The change from fmt.Errorf to errors.New is correct here as the error message is a static string with no parameters.


820-820: LGTM: Appropriate use of errors.New

The change from fmt.Errorf to errors.New is correct here as the error message is a static string with no parameters.

CONTRIBUTING.md (1)

245-245: LGTM: Error message format change is consistent with the PR objective.

The change from using fmt.Errorf to errors.New with a pre-formatted error message aligns with the PR's goal of standardizing error handling.

x/gamm/pool-models/balancer/pool.go (3)

144-144: LGTM: Consistent error handling for token balance validation.

The change from fmt.Errorf to errors.New maintains the same error message while standardizing the error creation pattern.


153-153: LGTM: Consistent error handling for duplicate pool assets.

The change from fmt.Errorf to errors.New maintains the same error message while standardizing the error creation pattern.


304-304: LGTM: Consistent error handling for pool asset balance updates.

The change from fmt.Errorf to errors.New maintains the same error message while standardizing the error creation pattern.

@czarcas7ic
Copy link
Member

Important note to contributors: We deeply value your contributions. However, due to a large influx of airdrop hunters, we are currently unable to accept small lint changes from first-time contributors. We encourage you to look for issues that offer more substantial contributions to the project or issues from the good first issue label. This helps us maintain the quality and integrity of the codebase, and provides a more meaningful experience for you as a contributor.

@czarcas7ic czarcas7ic closed this Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:CLI C:simulator Edits simulator or simulations C:x/gamm Changes, features and bugs related to the gamm module.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants