Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 58 additions & 8 deletions src/fix/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,74 @@ pub fn process_python_rules(
continue;
}
};
let match_func = module.getattr("match")?;
let fix_func = module.getattr("fix")?;
let match_func = match module.getattr("match") {
Ok(func) => func,
Err(e) => {
eprintln!(
"{}{}{}",
"Failed to get 'match' function from rule '".yellow(),
rule_path.display(),
"': ".yellow(),
);
eprintln!("{e}");
continue;
}
};
let fix_func = match module.getattr("fix") {
Ok(func) => func,
Err(e) => {
eprintln!(
"{}{}{}",
"Failed to get 'fix' function from rule '".yellow(),
rule_path.display(),
"': ".yellow(),
);
eprintln!("{e}");
continue;
}
};
if match_func.is_callable() && fix_func.is_callable() {
if match_func
let is_match = match match_func
.call1((
command.command(),
command.output().stdout(),
command.output().stderr(),
))?
.extract::<bool>()?
))
.and_then(|result| result.extract::<bool>())
{
let fixed_command: String = fix_func
Ok(result) => result,
Err(e) => {
eprintln!(
"{}{}{}",
"Failed to execute 'match' function in rule '".yellow(),
rule_path.display(),
"': ".yellow(),
);
eprintln!("{e}");
continue;
}
};
if is_match {
let fixed_command: String = match fix_func
.call1((
command.command(),
command.output().stdout(),
command.output().stderr(),
))?
.extract()?;
))
.and_then(|result| result.extract())
{
Ok(cmd) => cmd,
Err(e) => {
eprintln!(
"{}{}{}",
"Failed to execute 'fix' function in rule '".yellow(),
rule_path.display(),
"': ".yellow(),
);
eprintln!("{e}");
continue;
}
};
Comment on lines +76 to +143
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

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

The new error handling logic for Python rule processing lacks test coverage. Consider adding unit tests that verify:

  • Error handling when getattr("match") fails
  • Error handling when getattr("fix") fails
  • Error handling when match_func.call1() fails
  • Error handling when fix_func.call1() fails
  • Verification that the loop continues processing other rules after an error

These tests would help ensure the error handling behaves correctly and prevent regressions. Other modules in src/fix/ (like rust.rs and individual rule files) have comprehensive test coverage that could serve as examples.

Copilot uses AI. Check for mistakes.
fixed_commands.push(fixed_command);
}
} else {
Expand Down