-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
feat: check latest block if no arg in q block
and q block-results
#21084
Conversation
WalkthroughWalkthroughThe changes in the command handling logic enhance the flexibility of the CLI by allowing commands to accept zero or one argument for block height. This modification ensures backward compatibility while simplifying error handling and streamlining the internal logic of the command, thereby improving the user experience and robustness. Changes
Assessment against linked issues
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configuration File (
|
I am adding a changelog in the v0.50 backport only. |
There was a problem hiding this 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
Outside diff range, codebase verification and nitpick comments (2)
server/cmt_cmds.go (2)
252-258
: User Experience: Informative fallback message.The message "Falling back to latest block height:" enhances user experience by informing them about the fallback behavior.
Consider using
cmd.Printf
instead ofcmd.Println
for consistency with other logging statements.- cmd.Println("Falling back to latest block height:") + cmd.Printf("Falling back to latest block height:\n")
332-336
: User Experience: Informative fallback message.The message "Falling back to latest block height:" enhances user experience by informing them about the fallback behavior.
Consider using
cmd.Printf
instead ofcmd.Println
for consistency with other logging statements.- cmd.Println("Falling back to latest block height:") + cmd.Printf("Falling back to latest block height:\n")
Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Files selected for processing (1)
- server/cmt_cmds.go (3 hunks)
Additional context used
Path-based instructions (1)
server/cmt_cmds.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
Additional comments not posted (3)
server/cmt_cmds.go (3)
230-230
: Correctness: Allow zero or one argument.The change from
cobra.ExactArgs(1)
tocobra.MaximumNArgs(1)
correctly allows the command to accept zero or one argument, restoring the previous functionality.
238-242
: Logic: Handle zero arguments gracefully.The new conditional logic correctly defaults the
typ
variable toauth.TypeHeight
when no arguments are provided, ensuring backward compatibility.
325-336
: Correctness: Handle zero arguments gracefully.The new conditional logic correctly handles the case where no arguments are provided by fetching the latest block height.
server/cmt_cmds.go
Outdated
var ( | ||
err error | ||
height int64 | ||
) | ||
heightStr := args[0] | ||
|
||
if heightStr == "" { | ||
cmd.Println("Falling back to latest block height:") | ||
height, err = rpc.GetChainHeight(clientCtx) | ||
if err != nil { | ||
return fmt.Errorf("failed to get chain height: %w", err) | ||
} | ||
} else { | ||
height, err = strconv.ParseInt(heightStr, 10, 64) | ||
if err != nil { | ||
return err | ||
return fmt.Errorf("failed to parse block height: %w", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error Handling: Improve parsing logic.
The parsing logic for heightStr
is improved, but there is a potential issue if args[0]
is accessed when args
is empty.
- heightStr := args[0]
+ heightStr := ""
+ if len(args) > 0 {
+ heightStr = args[0]
+ }
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.
var ( | |
err error | |
height int64 | |
) | |
heightStr := args[0] | |
if heightStr == "" { | |
cmd.Println("Falling back to latest block height:") | |
height, err = rpc.GetChainHeight(clientCtx) | |
if err != nil { | |
return fmt.Errorf("failed to get chain height: %w", err) | |
} | |
} else { | |
height, err = strconv.ParseInt(heightStr, 10, 64) | |
if err != nil { | |
return err | |
return fmt.Errorf("failed to parse block height: %w", err) | |
var ( | |
err error | |
height int64 | |
) | |
heightStr := "" | |
if len(args) > 0 { | |
heightStr = args[0] | |
} | |
if heightStr == "" { | |
cmd.Println("Falling back to latest block height:") | |
height, err = rpc.GetChainHeight(clientCtx) | |
if err != nil { | |
return fmt.Errorf("failed to get chain height: %w", err) | |
} | |
} else { | |
height, err = strconv.ParseInt(heightStr, 10, 64) | |
if err != nil { | |
return fmt.Errorf("failed to parse block height: %w", err) |
There was a problem hiding this 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
Files selected for processing (1)
- server/cmt_cmds.go (3 hunks)
Additional context used
Path-based instructions (1)
server/cmt_cmds.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
Additional comments not posted (4)
server/cmt_cmds.go (4)
230-230
: Allow zero or one argument for block height.Changing the
Args
property tocobra.MaximumNArgs(1)
allows the command to accept zero or one argument, improving flexibility.
238-242
: Handle cases where no arguments are provided.The new conditional check ensures that the command defaults to querying by height if no arguments are provided, maintaining backward compatibility.
246-264
: Improved parsing logic for block height.The logic for parsing the block height has been updated to handle cases where no arguments are provided, falling back to the latest block height if necessary. Error handling has been enhanced.
328-339
: Handle cases where no arguments are provided.The new conditional check ensures that the command falls back to the latest block height if no arguments are provided, improving flexibility and user experience.
Description
Closes: #21081
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
in the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.
I have...
Summary by CodeRabbit