Repository navigation
fix: name the setting behind a regex that will not compile - #574
Conversation
Closes #497. message_pattern, author_name_pattern, author_email_pattern and the [tag] regex hold a regular expression the user wrote. An unusable one was only noticed on its first re.match, deep inside a validator, where main's catch-all printed the bare text from re and returned exit code 1: $ commit-check --author-name --author-name-pattern='[' Error: unterminated character set at position 0 $ echo $? 1 Nothing said which of the four settings held it, and exit code 1 is the code a rejected commit gets -- so #570, which had just made exit code 2 mean "the policy is broken, nothing was judged", had a hole in it: a CI wrapper reads a typo'd pattern as a rejected commit. Compile each of the four while the rule is built and report a failure as a ConfigError, which the CLI already returns as exit code 2: Error: [commit] author_name_pattern is not a valid regex: '[' (unterminated character set at position 0) These four can come from the file, a --flag or a CCHK_* variable, and the merged config no longer remembers which. main() prefixes a ConfigError with the config file it found, which for these would be a guess -- and a wrong one for a value passed on the command line. ConfigError carries the setting name for that case, and main() leaves the file out when it is set; the warn list, which has no flag or env form, still names the file. A valid pattern is unaffected, and an empty [tag] regex still means "do not match tags" rather than "compile an empty regex". prohibited_patterns and require_rebase_target are left alone: the first is matched with fnmatchcase, the second is stripped of anchors and resolved as a branch name. Neither is ever compiled.
|
Warning Review limit reachedNext included review available in 38 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (6)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #574 +/- ##
=======================================
Coverage 99.03% 99.04%
=======================================
Files 13 13
Lines 1866 1881 +15
=======================================
+ Hits 1848 1863 +15
Misses 18 18 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Heads-up: one expected conflict with the sibling PR. #573 and #574 both touch the module-level helpers at the top of |
|
Merging this PR will not alter performance
Comparing Footnotes
|



Closes #497.
Why now
#570made exit code2mean "the policy is broken, nothing was judged" and wrote that contract into the README and--help. A regex the user supplied that does not compile is exactly that case, and it was not covered — it came back as exit code1, the code a rejected commit gets:Two things are wrong there. The message does not say which of the settings holds the pattern, and a CI wrapper (or
--format json) reads a typo'd config as a rejected commit. The pattern only fails on its firstre.match, deep inside a validator, wheremain()'s catch-all prints the bare text fromre.What changed
The four settings that really are compiled —
[commit] message_pattern,[commit] author_name_pattern,[commit] author_email_pattern,[tag] regex— are compiled while the rule is built, and a failure is aConfigError, which the CLI already returns as exit code2:Not blaming the wrong file
These four can arrive from the config file, a
--flag, or aCCHK_*variable, and the merged dict no longer remembers which.main()prefixes aConfigErrorwith the config file it found — correct forwarn, which has no flag or env form, but a guess here, and a wrong one for a value passed on the command line.ConfigErrornow carries the setting name for that case andmain()leaves the file out when it is set. Thewarnerror still names the file, unchanged.Deliberately out of scope
prohibited_patternsis matched withfnmatchcase(a glob, not a regex) andrequire_rebase_targetis stripped of anchors and resolved as a branch name withgit rev-parse. Neither is ever compiled, so neither is checked.allow_branch_types/allow_branch_namesare not touched here either: onmainthey arere.escaped, so any value compiles. #573 restores them to patterns — once that lands, the same check applies to them and I am happy to add it as a follow-up commit to whichever of the two merges second.Tests
+12, full suite 966 passed.
tests/rule_builder_test.py::TestInvalidUserRegexNamesTheSetting— each of the four settings raisesConfigError, naming the setting, echoing the pattern, and keepingre's own reason (so the position survives); valid patterns build; an empty[tag] regexstill disables the match rather than compiling"".tests/main_test.py::TestInvalidUserRegexIsAConfigError— exit code2end to end; a pattern from a flag does not name an unrelated config file that happens to exist;--tag-regexlikewise.README: the exit-code table now lists "a setting whose regex does not compile" under
2, with the new message shown.README
rev:pins stay atv2.17.0— still the latest published release on PyPI, per AGENTS.md.