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

Closed
wants to merge 0 commits into from

Conversation

0x2d3c
Copy link
Contributor

@0x2d3c 0x2d3c commented Jun 10, 2024

Summary by CodeRabbit

  • Bug Fixes

    • Standardized error message creation across various functions for improved consistency and clarity.
  • Documentation

    • Updated error handling logic to use errors.New instead of fmt.Errorf in multiple files for more descriptive messages.

Copy link
Contributor

coderabbitai bot commented Jun 10, 2024

Walkthrough

Walkthrough

This update focuses on standardizing error handling across various files within the project. The main change involves replacing instances of fmt.Errorf with errors.New for creating error messages. Additionally, some error messages are modified for clarity and consistency. This enhances code readability and maintains a uniform approach to error handling, leveraging the errors package throughout the codebase.

Changes

Files Change Summary
client/rpc/tx.go, client/v2/autocli/flag/coin.go, client/v2/autocli/flag/pubkey.go, etc. Replaced fmt.Errorf with errors.New; updated import statements and error messages accordingly.
x/auth/client/cli/query.go, x/authz/client/cli/tx.go, x/crisis/types/genesis.go, etc. Standardized error handling by using errors.New; replaced fmt.Errorf across several files in initialization, validation, etc.
store/v2/root/factory.go Changed from fmt.Errorf to errors.New for error handling in CreateRootStore function.
runtime/v2/manager.go Updated error handling in RunMigrations method to use errors.New.
x/protocolpool/keeper/keeper.go Replaced error message creation from fmt.Errorf to errors.New for various fund distribution and budget proposal functions.

Sequence Diagram(s)

Diagram generation skipped as the changes are straightforward standardizations in error handling across various files.


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

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: 12

Outside diff range and nitpick comments (2)
x/auth/client/cli/query.go (2)

Line range hint 203-203: Improve error message clarity for missing 'denom' field.

The error message for a missing 'denom' field should be clearer to help users understand the expected input structure.

- return errors.New("expected denom field")
+ return errors.New("expected 'denom' field is missing. Ensure the coin denomination is specified.")

Line range hint 210-210: Enhance error handling for missing 'amount' field.

The error message for a missing 'amount' field should provide more context to help users correct their input.

- return errors.New("expected amount field")
+ return errors.New("expected 'amount' field is missing. Please specify the amount in the input.")
Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7fb2668 and 9a192fd.

Files selected for processing (22)
  • client/rpc/tx.go (4 hunks)
  • client/v2/autocli/flag/coin.go (2 hunks)
  • client/v2/autocli/flag/pubkey.go (2 hunks)
  • client/v2/autocli/query.go (3 hunks)
  • client/v2/offchain/verify.go (1 hunks)
  • runtime/v2/manager.go (1 hunks)
  • store/v2/root/factory.go (2 hunks)
  • telemetry/metrics.go (3 hunks)
  • testutil/key.go (2 hunks)
  • testutil/sims/app_helpers.go (2 hunks)
  • tools/cosmovisor/args.go (1 hunks)
  • x/auth/client/cli/query.go (6 hunks)
  • x/authz/client/cli/tx.go (2 hunks)
  • x/crisis/types/genesis.go (2 hunks)
  • x/distribution/types/params.go (2 hunks)
  • x/evidence/types/genesis.go (2 hunks)
  • x/genutil/types/genesis.go (1 hunks)
  • x/genutil/utils.go (2 hunks)
  • x/protocolpool/keeper/keeper.go (7 hunks)
  • x/staking/keeper/slash.go (2 hunks)
  • x/staking/types/authz.go (3 hunks)
  • x/upgrade/keeper/migrations.go (2 hunks)
Files not reviewed due to errors (2)
  • x/crisis/types/genesis.go (no review received)
  • client/v2/autocli/query.go (no review received)
Files skipped from review due to trivial changes (4)
  • client/v2/offchain/verify.go
  • testutil/key.go
  • x/staking/keeper/slash.go
  • x/upgrade/keeper/migrations.go
Additional context used
Path-based instructions (18)
x/crisis/types/genesis.go (1)

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

x/distribution/types/params.go (1)

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

client/v2/autocli/flag/coin.go (1)

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

client/v2/autocli/flag/pubkey.go (1)

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

x/evidence/types/genesis.go (1)

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

store/v2/root/factory.go (1)

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

x/genutil/utils.go (1)

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

client/rpc/tx.go (1)

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

x/auth/client/cli/query.go (1)

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

x/genutil/types/genesis.go (1)

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

client/v2/autocli/query.go (1)

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

x/staking/types/authz.go (1)

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

telemetry/metrics.go (1)

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

x/authz/client/cli/tx.go (1)

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

testutil/sims/app_helpers.go (1)

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

x/protocolpool/keeper/keeper.go (1)

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

tools/cosmovisor/args.go (1)

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

runtime/v2/manager.go (1)

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

Additional comments not posted (18)
client/v2/autocli/flag/coin.go (1)

41-41: The change to errors.New enhances clarity and consistency in error handling.

x/evidence/types/genesis.go (1)

48-48: The change from fmt.Errorf to errors.New in the Validate function enhances clarity and consistency in error handling.

store/v2/root/factory.go (1)

96-96: Using errors.New for the unsupported feature in CreateRootStore aligns with the PR's goal of standardizing error handling.

x/genutil/utils.go (1)

56-56: Replacing fmt.Errorf with errors.New for the invalid mnemonic error in InitializeNodeValidatorFilesFromMnemonic enhances error message clarity.

client/rpc/tx.go (2)

191-191: Using sdkerrors.ErrLogic.Wrapf for the timeout error in WaitTxCmd provides a more specific and informative error message.


218-218: The use of errors.New for the missing txhash error in parseHashFromInput simplifies and clarifies the error creation.

x/auth/client/cli/query.go (1)

139-139: Handle multiple transactions for a single signature more gracefully.

The error handling for multiple transactions matching a single signature should provide more context or a potential resolution path for the user.

- return errors.New("found no txs matching given signatures")
+ return errors.New("multiple transactions found for the given signature, which is unexpected. Please contact support if this issue persists.")

Likely invalid or redundant comment.

telemetry/metrics.go (3)

13-13: The import of github.com/pkg/errors is correctly added to replace fmt.Errorf with errors.New for error handling.


196-196: Correct replacement of fmt.Errorf with errors.New for the error message when Prometheus metrics are not enabled.


222-222: Proper use of errors.New in place of fmt.Errorf for the error message when the non in-memory metrics sink does not support the generic format.

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

140-140: Correctly replaced fmt.Errorf with errors.New for the error message when the spend limit is not positive.


205-205: Proper use of errors.New in place of fmt.Errorf for the error message when the spend limit for staking-related authorizations is not positive.

testutil/sims/app_helpers.go (2)

5-5: The import of the errors package is correctly added to replace fmt.Errorf with errors.New for error handling.


168-168: Correct replacement of fmt.Errorf with errors.New for the error message when creating a validator set fails.

x/protocolpool/keeper/keeper.go (2)

434-434: Correctly replaced fmt.Errorf with errors.New for various validation error messages in the budget proposal validation. This change enhances the clarity of the error messages.

Also applies to: 447-447, 451-451, 455-455


474-474: Proper use of errors.New in place of fmt.Errorf for various error messages in the continuous fund validation. This change is consistent with the PR's objective to standardize error handling.

Also applies to: 477-477, 480-480, 486-486

tools/cosmovisor/args.go (1)

313-313: Replace fmt.Errorf with errors.New for consistency.

- return 0, fmt.Errorf("could not parse '%s' into a duration: %w", input, err)
+ return 0, errors.New("could not parse input into a duration")

Likely invalid or redundant comment.

runtime/v2/manager.go (1)

408-408: Replace fmt.Errorf with errors.New for consistency.

- return nil, fmt.Errorf("validator InitGenesis update is already set by another module")
+ return nil, errors.New("validator InitGenesis update is already set by another module")

Likely invalid or redundant comment.

@@ -207,7 +207,7 @@ func (k Keeper) SetToDistribute(ctx context.Context, amount sdk.Coins, addr stri
return false, nil
})
if totalStreamFundsPercentage.GT(math.NewInt(100)) {
return fmt.Errorf("total funds percentage cannot exceed 100")
return errors.New("total funds percentage cannot exceed 100")
Copy link
Contributor

Choose a reason for hiding this comment

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

The use of errors.New instead of fmt.Errorf for the error message when the total funds percentage exceeds 100 is correctly implemented. However, this message is duplicated in two different methods (SetToDistribute and iterateAndUpdateFundsDistribution). Consider extracting this error generation to a common method or constant to avoid duplication and ensure consistency.

Also applies to: 277-277

@@ -28,7 +29,7 @@ func validateCommunityTax(i interface{}) error {
}

if v.IsNil() {
return fmt.Errorf("community tax must be not nil")
return errors.New("community tax must be not nil")
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace remaining fmt.Errorf with errors.New for consistency.

- return fmt.Errorf("community tax must be positive: %s", v)
+ return errors.New("community tax must be positive: " + v.String())
- return fmt.Errorf("community tax too large: %s", v)
+ return errors.New("community tax too large: " + v.String())
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return errors.New("community tax must be not nil")
return errors.New("community tax must be not nil")
return errors.New("community tax must be positive: " + v.String())
return errors.New("community tax too large: " + v.String())

@@ -47,7 +48,7 @@ func (a *pubkeyValue) Set(s string) error {

any, err := types.NewAnyWithValue(pk)
if err != nil {
return fmt.Errorf("error converting to any type")
return errors.New("error converting to any type")
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace fmt.Errorf with errors.New for consistency.

- return fmt.Errorf("input isn't a pubkey: %w", err)
+ return errors.New("input isn't a pubkey: " + err.Error())
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return errors.New("error converting to any type")
return errors.New("error converting to any type")
return errors.New("input isn't a pubkey: " + err.Error())

@@ -183,7 +184,7 @@ $ %s query tx --%s=%s <sig1_base64>,<sig2_base64...>
// ParseSigArgs parses comma-separated signatures from the CLI arguments.
func ParseSigArgs(args []string) ([]string, error) {
if len(args) != 1 || args[0] == "" {
return nil, fmt.Errorf("argument should be comma-separated signatures")
return nil, errors.New("argument should be comma-separated signatures")
Copy link
Contributor

Choose a reason for hiding this comment

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

Clarify expected structure for duration encoding.

The error message when the 'nanos' field is missing should guide the user or developer on what is expected.

- return errors.New("expected nanos field")
+ return errors.New("expected 'nanos' field is missing in the input. Ensure the duration is correctly formatted.")

Committable suggestion was skipped due to low confidence.

}
if len(txs.Txs) > 1 {
// This case means there's a bug somewhere else in the code as this
// should not happen.
return errors.ErrLogic.Wrapf("found %d txs matching given signatures", len(txs.Txs))
return sdkerrors.ErrLogic.Wrapf("found %d txs matching given signatures", len(txs.Txs))
Copy link
Contributor

Choose a reason for hiding this comment

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

Use specific error types for better error handling.

Instead of using a generic error, consider using a specific error type that can be caught and handled differently depending on the context.

- return sdkerrors.ErrLogic.Wrapf("found %d txs matching given signatures", len(txs.Txs))
+ return sdkerrors.ErrMultipleTransactionsFound.Wrapf("found %d txs matching given signatures", len(txs.Txs))
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return sdkerrors.ErrLogic.Wrapf("found %d txs matching given signatures", len(txs.Txs))
return sdkerrors.ErrMultipleTransactionsFound.Wrapf("found %d txs matching given signatures", len(txs.Txs))

}

return clientCtx.PrintProto(txs.Txs[0])

case TypeAccSeq:
if args[0] == "" {
return fmt.Errorf("`acc_seq` type takes an argument '<addr>/<seq>'")
return errors.New("`acc_seq` type takes an argument '<addr>/<seq>'")
Copy link
Contributor

Choose a reason for hiding this comment

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

Clarify the error message for missing acc_seq argument.

The error message for a missing acc_seq argument should be more descriptive to help the user understand what is expected.

- return errors.New("`acc_seq` type takes an argument '<addr>/<seq>'")
+ return errors.New("`acc_seq` type requires a non-empty argument in the format '<addr>/<seq>'")

@@ -209,7 +209,7 @@ func (cs *ConsensusGenesis) UnmarshalJSON(b []byte) error {

func (cs *ConsensusGenesis) ValidateAndComplete() error {
if cs == nil {
return fmt.Errorf("consensus genesis cannot be nil")
return errors.New("consensus genesis cannot be nil")
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure non-nullity of critical configuration components.

The error message when the consensus genesis is null should explicitly state the necessity of this configuration for operation.

- return errors.New("consensus genesis cannot be nil")
+ return errors.New("consensus genesis configuration is required and cannot be nil. Please provide a valid configuration.")
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return errors.New("consensus genesis cannot be nil")
return errors.New("consensus genesis configuration is required and cannot be nil. Please provide a valid configuration.")

@@ -64,12 +64,12 @@ func (a StakeAuthorization) MsgTypeURL() string {
// is unspecified.
func (a StakeAuthorization) ValidateBasic() error {
if a.MaxTokens != nil && a.MaxTokens.IsNegative() {
return errorsmod.Wrapf(fmt.Errorf("max tokens should be positive"),
return errorsmod.Wrapf(errors.New("max tokens should be positive"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Use specific error types for domain-specific errors.

Instead of using a generic error, consider using a specific error type that can be caught and handled differently depending on the context.

- return errorsmod.Wrapf(errors.New("max tokens should be positive"),
- "negative coin amount: %v", a.MaxTokens)
+ return sdkerrors.ErrNegativeAmount.Wrapf("negative coin amount: %v", a.MaxTokens)
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return errorsmod.Wrapf(errors.New("max tokens should be positive"),
return sdkerrors.ErrNegativeAmount.Wrapf("negative coin amount: %v", a.MaxTokens)

"negative coin amount: %v", a.MaxTokens)
}

if a.AuthorizationType == AuthorizationType_AUTHORIZATION_TYPE_UNSPECIFIED {
return fmt.Errorf("unknown authorization type")
return errors.New("unknown authorization type")
Copy link
Contributor

Choose a reason for hiding this comment

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

Clarify the error message for unspecified authorization types.

The error message for an unspecified authorization type should be more descriptive to help the user understand what is expected.

- return errors.New("unknown authorization type")
+ return errors.New("authorization type is unspecified or unknown. Please provide a valid authorization type.")
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return errors.New("unknown authorization type")
return errors.New("authorization type is unspecified or unknown. Please provide a valid authorization type.")

@@ -220,7 +220,7 @@
case AuthorizationType_AUTHORIZATION_TYPE_CANCEL_UNBONDING_DELEGATION:
return sdk.MsgTypeURL(&MsgCancelUnbondingDelegation{}), nil
default:
return "", errorsmod.Wrapf(fmt.Errorf("unknown authorization type"),
return "", errorsmod.Wrapf(errors.New("unknown authorization type"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Provide more detailed error information for unknown authorization types.

The error message when an authorization type is unknown should include suggestions or possible values to guide the user.

- return "", errorsmod.Wrapf(errors.New("unknown authorization type"),
- "cannot normalize authz type with %T", authzType)
+ return "", errorsmod.Wrapf(errors.New("unknown authorization type. Valid types include: delegate, undelegate, redelegate, cancel_unbonding_delegation"),
+ "received authorization type: %T", authzType)
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return "", errorsmod.Wrapf(errors.New("unknown authorization type"),
return "", errorsmod.Wrapf(errors.New("unknown authorization type. Valid types include: delegate, undelegate, redelegate, cancel_unbonding_delegation"),
"received authorization type: %T", authzType)

telemetry/metrics.go Outdated Show resolved Hide resolved
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 9a192fd and ba944c1.

Files selected for processing (1)
  • telemetry/metrics.go (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • telemetry/metrics.go

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 ba944c1 and e655511.

Files selected for processing (1)
  • testutil/sims/app_helpers.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • testutil/sims/app_helpers.go

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: 1

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e655511 and 63da776.

Files selected for processing (1)
  • x/genutil/utils.go (2 hunks)
Additional context used
Path-based instructions (1)
x/genutil/utils.go (1)

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

golangci-lint
Additional comments not posted (1)
x/genutil/utils.go (1)

58-58: Change aligns with PR objectives to standardize error handling by using errors.New for static error messages.

@@ -54,7 +55,7 @@ func InitializeNodeValidatorFiles(config *cfg.Config, keyType string) (nodeID st
// If no valid mnemonic is given, a random one will be used instead.
func InitializeNodeValidatorFilesFromMnemonic(config *cfg.Config, mnemonic, keyType string) (nodeID string, valPubKey cryptotypes.PubKey, err error) {
if len(mnemonic) > 0 && !bip39.IsMnemonicValid(mnemonic) {
return "", nil, fmt.Errorf("invalid mnemonic")
return "", nil, errors.New("invalid mnemonic")
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using fmt.Errorf consistently for errors that involve variable data or need to wrap another error, to maintain consistency in error handling throughout the function.

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 63da776 and 8576196.

Files selected for processing (2)
  • client/rpc/tx.go (4 hunks)
  • x/protocolpool/keeper/keeper.go (7 hunks)
Files skipped from review as they are similar to previous changes (2)
  • client/rpc/tx.go
  • x/protocolpool/keeper/keeper.go

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 8576196 and cac8310.

Files selected for processing (1)
  • client/rpc/tx.go (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • client/rpc/tx.go

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 cac8310 and 1c380b6.

Files selected for processing (1)
  • x/genutil/utils.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/genutil/utils.go

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 1c380b6 and 2ef9270.

Files selected for processing (2)
  • client/v2/autocli/flag/coin.go (2 hunks)
  • client/v2/autocli/flag/pubkey.go (2 hunks)
Files skipped from review as they are similar to previous changes (2)
  • client/v2/autocli/flag/coin.go
  • client/v2/autocli/flag/pubkey.go

@tac0turtle
Copy link
Member

this pr has been a battle, i apoligise

@0x2d3c
Copy link
Contributor Author

0x2d3c commented Jun 21, 2024

this pr has been a battle, i apoligise

Some checks have not been passed, causing auto merging to fail. Is there a way to avoid this?

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: 1

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2ef9270 and b52ebca.

Files selected for processing (1)
  • x/staking/keeper/slash.go (2 hunks)
Additional context used
Path-based instructions (1)
x/staking/keeper/slash.go (1)

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

Additional comments not posted (1)
x/staking/keeper/slash.go (1)

193-193: Replace fmt.Errorf with errors.New for consistency.

In line with the PR objective to replace fmt.Errorf with errors.New when no formatting parameters are used, this instance should be updated to maintain consistency across the codebase.

- return math.NewInt(0), fmt.Errorf("invalid validator status")
+ return math.NewInt(0), errors.New("invalid validator status")

Likely invalid or redundant comment.

@@ -411,7 +411,7 @@ func (k Keeper) SlashRedelegation(ctx context.Context, srcValidator types.Valida
case dstValidator.IsUnbonded() || dstValidator.IsUnbonding():
notBondedBurnedAmount = notBondedBurnedAmount.Add(tokensToBurn)
default:
return math.ZeroInt(), fmt.Errorf("unknown validator status")
return math.ZeroInt(), errors.New("unknown validator status")
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace fmt.Errorf with errors.New for consistency.

Similar to previous comments, this line should also be updated to use errors.New instead of fmt.Errorf since no formatting parameters are used, aligning with the overall refactoring goal of this PR.

- return math.ZeroInt(), fmt.Errorf("unknown validator status")
+ return math.ZeroInt(), errors.New("unknown validator status")

Committable suggestion was skipped due to low confidence.

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 b52ebca and 9674043.

Files selected for processing (2)
  • store/v2/root/factory.go (2 hunks)
  • x/protocolpool/keeper/keeper.go (7 hunks)
Additional context used
Path-based instructions (2)
store/v2/root/factory.go (1)

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

x/protocolpool/keeper/keeper.go (1)

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

Additional comments not posted (13)
store/v2/root/factory.go (1)

96-96: Refactor to errors.New approved.

The change from fmt.Errorf to errors.New for the "iavl v2 not supported" error aligns with the PR's objective of standardizing error handling. This is a good use of errors.New since there are no formatting directives needed.

x/protocolpool/keeper/keeper.go (12)

210-210: Refactor to errors.New approved.

This change correctly implements the PR's objective. The error message "total funds percentage cannot exceed 100" is now consistently generated using errors.New, which is suitable as there are no formatting parameters.


295-295: Refactor to errors.New approved.

The duplication of the error message "total funds percentage cannot exceed 100" has been addressed by using errors.New consistently. This maintains the consistency and clarity of error messages across different methods.


393-393: Refactor to errors.New approved.

The error message "distribution has not started yet" is now generated using errors.New, aligning with the PR's objective to standardize error handling. This change is appropriate as the message does not require any dynamic values.


411-411: Refactor to errors.New approved.

The error "budget period has not passed yet" is now properly handled using errors.New. This change improves the consistency and readability of the error handling in the code.


452-452: Refactor to errors.New approved.

The error "invalid budget proposal: budget per tranche cannot be zero" is now created using errors.New, which is correct for static error messages and aligns with the PR's aim.


465-465: Refactor to errors.New approved.

The error "invalid budget proposal: start time cannot be less than the current block time" has been correctly refactored to use errors.New, enhancing the consistency of error handling.


469-469: Refactor to errors.New approved.

The error "invalid budget proposal: tranches must be greater than zero" is now generated using errors.New. This is a good practice for static error messages.


473-473: Refactor to errors.New approved.

The error "invalid budget proposal: period length should be greater than zero" is now created using errors.New, which is suitable for static error messages and enhances the clarity and maintainability of the code.


492-492: Refactor to errors.New approved.

The error "percentage cannot be zero or empty" is appropriately handled using errors.New, aligning with the objective to standardize error creation.


495-495: Refactor to errors.New approved.

The change to use errors.New for the error "percentage cannot be negative" is consistent with the PR's goals and improves the error handling standardization.


498-498: Refactor to errors.New approved.

The error "percentage cannot be greater than or equal to one" is now generated using errors.New, which is a good practice for static error messages.


504-504: Refactor to errors.New approved.

The error "expiry time cannot be less than the current block time" has been correctly refactored to errors.New, which is appropriate for static error messages and aligns with the PR's aim.

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: 1

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9674043 and f69876f.

Files selected for processing (1)
  • runtime/v2/manager.go (1 hunks)
Additional context used
Path-based instructions (1)
runtime/v2/manager.go (1)

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

@@ -405,7 +405,7 @@ func (m *MM[T]) RunMigrations(ctx context.Context, fromVM appmodulev2.VersionMap

// The module manager assumes only one module will update the validator set, and it can't be a new module.
if len(moduleValUpdates) > 0 {
return nil, fmt.Errorf("validator InitGenesis update is already set by another module")
return nil, errors.New("validator InitGenesis update is already set by another module")
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider enhancing the error message by wrapping the existing error.

The replacement of fmt.Errorf with errors.New is aligned with the PR's objective to simplify error creation. However, consider using fmt.Errorf with error wrapping to provide more context in case of an error, which can be crucial for debugging.

- return nil, errors.New("validator InitGenesis update is already set by another module")
+ return nil, fmt.Errorf("validator InitGenesis update is already set by another module: %w", someErrorVar)

Please replace someErrorVar with the actual error variable that you would like to wrap.

Committable suggestion was skipped due to low confidence.

@tac0turtle tac0turtle disabled auto-merge June 28, 2024 08:29
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 f69876f and ee7b781.

Files selected for processing (1)
  • x/protocolpool/keeper/keeper.go (7 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/protocolpool/keeper/keeper.go

@0x2d3c
Copy link
Contributor Author

0x2d3c commented Jul 11, 2024

@tac0turtle Is this PR out of date and does it need to be resubmitted based on the latest code?

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.

4 participants