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

fix: improve error message from invalid pattern name #151

Merged
merged 13 commits into from
Apr 4, 2024
Merged

Conversation

seren5240
Copy link
Contributor

@seren5240 seren5240 commented Apr 4, 2024

fixes #134

Summary by CodeRabbit

  • Refactor
    • Enhanced module functionality by optimizing imports and removing duplicate code.
  • New Features
    • Introduced a new grit.yaml file for tagging errors and providing code transformations.
    • Added a new Button class in test files to extend component functionality.
  • Bug Fixes
    • Improved pattern name validation to ensure robust pattern handling.
  • Tests
    • Added a test to validate the behavior of commands with invalid names.
  • Documentation
    • Not explicitly mentioned, but changes imply an improvement in code documentation and debugging capabilities through the addition of debug attributes and error tagging.

Copy link
Contributor

coderabbitai bot commented Apr 4, 2024

Walkthrough

This update streamlines the handling and validation of pattern names within the codebase, particularly focusing on the removal of redundant declarations and enhancing the robustness of pattern name checks. By consolidating the is_pattern_name function and ensuring patterns are properly named and validated, the changes aim to make error messages more helpful and reduce confusion, especially when invalid characters are used in pattern names.

Changes

File Path Change Summary
.../src/commands/apply_pattern.rs, .../src/commands/plumbing.rs Consolidated is_pattern_name import, enhancing module functionality.
.../src/resolver.rs Added Debug trait to RichPattern struct.
.../src/utils.rs Removed redundant is_pattern_name function.
.../fixtures/config_invalid_name/.grit/grit.yaml, .../fixtures/config_invalid_name/test.js Introduced new files for testing invalid pattern names.
.../tests/apply.rs Added test for command failure with invalid pattern name.
.../gritmodule/src/config.rs, .../gritmodule/src/utils.rs Improved pattern name validation by adding is_pattern_name function.

Assessment against linked issues

Objective Addressed Explanation
Error message clarity when pattern name contains invalid characters [#134]
Ensure pattern name validation is consistent and robust [#134]

🐇✨

In the warren, deep and wide,
Where the code and patterns hide,
A rabbit worked with utmost care,
To fix the names that once were bare.

"No more confusion," it did decree,
With every hop, filled with glee.
Patterns now clear, and errors few,
A coderabbit's dream, finally true.

🌟🐾

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.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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/coderabbit-overrides.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.

@seren5240 seren5240 marked this pull request as ready for review April 4, 2024 05:39
@seren5240 seren5240 requested a review from a team April 4, 2024 05:39
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 Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between d0aa4d0 and feadcba.
Files ignored due to path filters (1)
  • crates/cli_bin/tests/snapshots/apply__config_pattern_with_invalid_name.snap is excluded by !**/*.snap
Files selected for processing (9)
  • crates/cli/src/commands/apply_pattern.rs (2 hunks)
  • crates/cli/src/commands/plumbing.rs (2 hunks)
  • crates/cli/src/resolver.rs (1 hunks)
  • crates/cli/src/utils.rs (2 hunks)
  • crates/cli_bin/fixtures/config_invalid_name/.grit/grit.yaml (1 hunks)
  • crates/cli_bin/fixtures/config_invalid_name/test.js (1 hunks)
  • crates/cli_bin/tests/apply.rs (1 hunks)
  • crates/gritmodule/src/config.rs (2 hunks)
  • crates/gritmodule/src/utils.rs (2 hunks)
Files not reviewed due to errors (1)
  • (no review received)
Additional comments not posted (7)
crates/cli_bin/fixtures/config_invalid_name/test.js (1)

1-3: LGTM! This JavaScript file is well-formed and serves its purpose as a test fixture.

crates/cli_bin/fixtures/config_invalid_name/.grit/grit.yaml (1)

1-9: LGTM! This .grit/grit.yaml file is correctly formatted and serves its purpose as a test fixture for invalid pattern names.

crates/cli/src/utils.rs (1)

1-1: The removal of the is_pattern_name function aligns with the PR's objective to centralize pattern name validation logic.

crates/cli/src/resolver.rs (1)

35-35: Adding the #[derive(Debug)] attribute to the RichPattern struct is a good practice for easier debugging.

crates/cli/src/commands/plumbing.rs (1)

8-8: Updating the import path for is_pattern_name to marzano_gritmodule::utils aligns with the PR's objective to centralize pattern name validation logic.

crates/gritmodule/src/config.rs (1)

276-278: Validating pattern names using is_pattern_name before processing enhances the robustness of pattern handling and aligns with the PR's objectives to improve error messaging.

crates/cli/src/commands/apply_pattern.rs (1)

21-21: Updating the import path for is_pattern_name to marzano_gritmodule::utils is consistent with the effort to centralize pattern name validation logic across the application.

Comment on lines +30 to +33
pub fn is_pattern_name(pattern: &str) -> bool {
let regex = Regex::new(r"^[a-zA-Z_][a-zA-Z0-9_]*(\(\))?$").unwrap();
regex.is_match(pattern)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace unwrap() with expect() when creating the regex to provide a clearer error message in case the regex pattern is invalid.

-    let regex = Regex::new(r"^[a-zA-Z_][a-zA-Z0-9_]*(\(\))?$").unwrap();
+    let regex = Regex::new(r"^[a-zA-Z_][a-zA-Z0-9_]*(\(\))?$").expect("Invalid regex pattern for is_pattern_name");

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.

Suggested change
pub fn is_pattern_name(pattern: &str) -> bool {
let regex = Regex::new(r"^[a-zA-Z_][a-zA-Z0-9_]*(\(\))?$").unwrap();
regex.is_match(pattern)
}
pub fn is_pattern_name(pattern: &str) -> bool {
let regex = Regex::new(r"^[a-zA-Z_][a-zA-Z0-9_]*(\(\))?$").expect("Invalid regex pattern for is_pattern_name");
regex.is_match(pattern)
}

@seren5240 seren5240 merged commit 81442f1 into main Apr 4, 2024
8 checks passed
@seren5240 seren5240 deleted the invalid-name branch April 4, 2024 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error message when pattern name contains invalid characters is confusing
2 participants