-
Notifications
You must be signed in to change notification settings - Fork 57
fix: fix disable analytic flag bug #1781
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
commit: |
crates/core/tests/utils_tests.rs
Outdated
| // #[test] | ||
| // fn test_parse_params_invalid() { | ||
| // // Test parsing invalid parameters | ||
| // let params = vec![ | ||
| // "key1=value1".to_string(), | ||
| // "invalid_param".to_string(), // Missing '=' | ||
| // ]; | ||
|
|
||
| // let result = utils::parse_params(¶ms); | ||
|
|
||
| // // Verify that parsing fails | ||
| // assert!(result.is_err()); | ||
| // match result { | ||
| // Err(Error::Other(msg)) => { | ||
| // assert!(msg.contains("Invalid parameter format")); | ||
| // } | ||
| // _ => panic!("Expected Other error"), | ||
| // } | ||
| // } |
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.
Why did you comment this out?
crates/core/src/utils.rs
Outdated
| println!( | ||
| "\x1b[33mWarning\x1b[0m: Invalid parameter format: {}", | ||
| param | ||
| ); | ||
| continue; |
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.
Is this change related? also we should use console::style for these ansi codes
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.
Pull Request Overview
This PR fixes a bug related to the disable analytics flag by modifying parameter parsing behavior and adding validation for the analytics flag usage. The change allows the system to handle invalid parameter formats more gracefully while ensuring proper usage of the disable analytics flag.
- Changed parameter parsing to emit warnings instead of errors for invalid formats
- Added validation to prevent misuse of the disable analytics flag in implicit run commands
- Commented out tests that verify error handling for invalid parameters
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| crates/core/src/utils.rs | Modified parse_params to continue with warnings instead of returning errors for invalid parameter formats |
| crates/core/tests/utils_tests.rs | Commented out test that verified error handling for invalid parameter parsing |
| crates/cli/src/main.rs | Added validation to ensure disable analytics flag is used correctly with explicit run command syntax |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
crates/core/src/utils.rs
Outdated
| println!( | ||
| "\x1b[33mWarning\x1b[0m: Invalid parameter format: {}", | ||
| param | ||
| ); |
Copilot
AI
Sep 18, 2025
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.
Using println! with hardcoded ANSI escape codes for colored output is not ideal. Consider using a proper logging framework or a colored output library like colored or termcolor for better maintainability and consistency.
crates/cli/src/main.rs
Outdated
| "--disable-analytics" | ||
| }; | ||
| return Err(anyhow::anyhow!( | ||
| "You can use disable-analytics flag like this: codemod run codemod-name -- {which_flag}" |
Copilot
AI
Sep 18, 2025
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.
The error message uses string interpolation syntax {which_flag} but this is not valid Rust string interpolation. It should use format! macro syntax or string formatting to properly substitute the variable value.
| "You can use disable-analytics flag like this: codemod run codemod-name -- {which_flag}" | |
| "You can use disable-analytics flag like this: codemod run codemod-name -- {}", which_flag |
0ec2d4c to
6dbffe1
Compare
crates/cli/src/commands/run.rs
Outdated
| #[arg(long)] | ||
| param: Option<Vec<String>>, |
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.
| #[arg(long)] | |
| param: Option<Vec<String>>, | |
| #[arg(long = "param", value_name = "KEY=VALUE")] | |
| params: Vec<String>, |
Also why do we need to make it Option? doesn't it yield an empty vector by default?
a10fb26 to
1a62671
Compare
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.
Pull Request Overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| let mut filtered_args = Vec::new(); | ||
| let mut disable_analytics = false; | ||
| let mut verbose = false; | ||
|
|
||
| for arg in &trailing_args { | ||
| match arg.as_str() { | ||
| "--disable-analytics" => { | ||
| disable_analytics = true; | ||
| } | ||
| "--verbose" | "-v" => { | ||
| verbose = true; | ||
| } | ||
| _ => { | ||
| filtered_args.push(arg.clone()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if disable_analytics { | ||
| std::env::set_var("DISABLE_ANALYTICS", "true"); | ||
| } | ||
| if verbose { | ||
| std::env::set_var("RUST_LOG", "debug"); | ||
| } | ||
|
|
||
| let mut full_args = vec!["codemod".to_string(), "run".to_string()]; | ||
| full_args.extend(trailing_args.clone()); | ||
| full_args.extend(filtered_args.clone()); | ||
|
|
||
| if disable_analytics { | ||
| full_args.push("--disable-analytics".to_string()); | ||
| } |
Copilot
AI
Sep 18, 2025
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.
This manual argument parsing duplicates the logic that clap already handles for global arguments. Since verbose and disable_analytics are now marked as global = true, clap should handle these automatically. Consider removing this manual parsing and letting clap handle the global arguments.
| if disable_analytics { | ||
| full_args.push("--disable-analytics".to_string()); | ||
| } | ||
| if verbose { | ||
| full_args.push("--verbose".to_string()); | ||
| } |
Copilot
AI
Sep 18, 2025
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.
These flags are being added back to full_args after being filtered out earlier, which creates unnecessary complexity. Since these are now global arguments, they should be handled by clap's global argument mechanism instead of this manual manipulation.
| if disable_analytics { | |
| full_args.push("--disable-analytics".to_string()); | |
| } | |
| if verbose { | |
| full_args.push("--verbose".to_string()); | |
| } | |
| // No need to manually re-add global flags; clap will handle them as global arguments. |
π Description
Things done in this PR:
-ββ-before calling them--no-telemetryargument to the legacy command