Skip to content

Conversation

@AsfhtgkDavid
Copy link
Owner

Description

fix #9

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Testing

  • Added unit tests
  • Manual testing performed
  • All existing tests pass

Checklist

  • Code follows project style
  • Self-review completed
  • Documentation updated
  • Tests added/updated

@codecov
Copy link

codecov bot commented Dec 4, 2025

Codecov Report

❌ Patch coverage is 0% with 45 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/fix/python.rs 0.00% 45 Missing ⚠️

❌ Your patch check has failed because the patch coverage (0.00%) is below the target coverage (60.00%). You can increase the patch coverage or adjust the target coverage.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #12      +/-   ##
==========================================
- Coverage   71.61%   69.67%   -1.94%     
==========================================
  Files          17       17              
  Lines        1335     1372      +37     
==========================================
  Hits          956      956              
- Misses        379      416      +37     
Files with missing lines Coverage Δ
src/fix/python.rs 0.00% <0.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

Copilot AI left a 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 improves error handling in the Python rules processing system by replacing panic-prone ? operators with explicit error handling that logs issues and continues processing remaining rules. This prevents a single failing rule from stopping the entire rule processing pipeline.

Key Changes:

  • Replaced ? operator with match expressions for all PyO3 operations (getattr, call1, extract)
  • Added descriptive error messages for each failure point (getting functions, executing functions)
  • Changed behavior from immediate propagation to logging errors and continuing with next rule

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +40 to +107
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;
}
};
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.
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.

[Bug]: One broken python rule breaks all python rules

2 participants