Skip to content

handle invalid command error#766

Merged
aknysh merged 1 commit intomainfrom
pulak/DEV-2323
Nov 7, 2024
Merged

handle invalid command error#766
aknysh merged 1 commit intomainfrom
pulak/DEV-2323

Conversation

@pkbhowmick
Copy link
Contributor

@pkbhowmick pkbhowmick commented Nov 7, 2024

what

why

working example

Before:

Screenshot 2024-11-08 at 1 56 30 AM

After fix:

Screenshot 2024-11-08 at 1 57 12 AM

references

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling for command arguments, providing clearer feedback when invalid commands are used.
    • Enhanced logging to include a list of available commands when an error occurs due to invalid arguments.

Signed-off-by: Pulak Kanti Bhowmick <pkbhowmick007@gmail.com>
@pkbhowmick pkbhowmick requested review from a team as code owners November 7, 2024 20:04
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 7, 2024

📝 Walkthrough

Walkthrough

The pull request modifies the preCustomCommand function in cmd/cmd_utils.go to enhance error handling. It introduces a conditional check for empty command arguments, logging an error if arguments are provided when none are expected. The error message includes available commands, improving user feedback. Additionally, the logging of errors has been adjusted to use an empty configuration, changing the previous error handling approach.

Changes

File Change Summary
cmd/cmd_utils.go Modified preCustomCommand to add a check for empty commandConfig.Arguments. Improved error logging for invalid commands.

Assessment against linked issues

Objective Addressed Explanation
Invalid custom commands should give an error that the command does not exist (DEV-2323)

Possibly related PRs

Suggested labels

patch

Suggested reviewers

  • osterman
  • johncblandii
  • gberenice
  • aknysh

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 or @auto-summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @auto-title anywhere in the PR title to generate the title automatically.

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

🧹 Outside diff range and nitpick comments (2)
cmd/cmd_utils.go (2)

171-171: Consider passing the CLI configuration context.

Currently using empty schema.CliConfiguration{} for logging. Consider passing the actual CLI configuration from the parent context for consistent logging behavior.

-			u.LogError(schema.CliConfiguration{}, errors.New("invalid command"))
+			u.LogError(cliConfig, errors.New("invalid command"))
-			u.LogInfo(schema.CliConfiguration{}, sb.String())
+			u.LogInfo(cliConfig, sb.String())

Also applies to: 176-176


172-175: Consider pre-allocating string builder capacity.

For better performance, consider pre-allocating the string builder's capacity based on the expected size of the command list.

-			sb.WriteString("Available command(s):\n")
+			// Pre-allocate buffer for average command length * number of commands
+			sb.Grow(len(commandConfig.Commands) * 50)
+			sb.WriteString("Available command(s):\n")
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 4098092 and 8087bb4.

📒 Files selected for processing (1)
  • cmd/cmd_utils.go (1 hunks)
🔇 Additional comments (1)
cmd/cmd_utils.go (1)

170-178: LGTM! Error handling improvement aligns with PR objectives.

The changes effectively address the PR objective by providing clearer error messages for invalid commands. The addition of available commands in the error output significantly improves user experience.

Copy link
Member

@aknysh aknysh left a comment

Choose a reason for hiding this comment

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

thanks @pkbhowmick

@aknysh aknysh added the patch A minor, backward compatible change label Nov 7, 2024
@aknysh aknysh merged commit 4617630 into main Nov 7, 2024
@aknysh aknysh deleted the pulak/DEV-2323 branch November 7, 2024 20:23
@github-actions
Copy link

github-actions bot commented Nov 7, 2024

These changes were released in v1.100.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

patch A minor, backward compatible change

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants