refactor: unify rule loading through merge_rules - #57
Conversation
… popping during rule loading
|
@juangaitanv and @Ibrahimrahhal have a look |
|
@juangaitanv have a look |
|
|
@juangaitanv You're completely right In commit 5ca93e7, we resolved this by removing the redundant |
🙏. could you address this comment pleaes #57 (comment)? |
…ge when no rules are found
|
@juangaitanv I've updated the PR with a regression unit test This test configures |
juangaitanv
left a comment
There was a problem hiding this comment.
Approving. The refactor is behavior-identical (merge_rules on a one-element vec reproduces the single-rules case, empty paths stay guarded) and the new tests pass.
One note on framing: the removed .unwrap() was provably safe under the len() == 1 guard, so this is a simplification, not a bug fix. Consider retitling the PR (e.g. "refactor: unify rule loading through merge_rules") so the history reflects that.
|
Thanks @juangaitanv for the review and approval! I've updated the PR title to |
Fixes #56
Description
This PR fixes a potential process panic (
called Option::unwrap() on a None value) insrc/scanner/modes.rswhen loading scan rules.Previously,
load_explicit_scan_rulesandload_rules_for_detected_languagecalled.unwrap()directly onall_rules.into_iter().next()when single-element rule lists were expected. If custom or file-based rules failed to yield matching definitions (e.g. when using--use-file-ruleswith an empty or non-matching rules directory), this resulted in an unhandled CLI thread panic.This change replaces
.unwrap()with safe.pop().ok_or_else(...)error handling that returns a cleananyhow::Result::Errto the user instead of panicking.Changes Made
src/scanner/modes.rs: Replaced.next().unwrap()calls with.pop().ok_or_else(...)and explicit empty-vector checks in bothload_explicit_scan_rulesandload_rules_for_detected_language.src/scanner/modes.rs: Added unit testload_explicit_scan_rules_handles_nonexistent_rules_gracefullyto prevent future regressions.Testing & Verification
cargo fmt.cargo test: all 105 unit tests and doc tests passed successfully.