Repository navigation
fix: refuse config values of the wrong type - #624
Conversation
A non-string pattern or a non-integer subject length now raises ConfigError naming the setting (exit 2), a comma-separated string of commit types, branch types or branch names is split as the CLI flag splits it, and the last-resort error handler names the exception type when its message is empty.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 56 minutes. View limit details
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 #624 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 14 14
Lines 2386 2407 +21
=========================================
+ Hits 2386 2407 +21 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Building the branch rule checked every item of the 21 default branch types on each run, about 0.6 us. CodSpeed flagged the allow_branch_names benchmarks as 10% slower. The built-in default is now returned unchecked, and a configured list is checked with a plain loop.
e606596 to
8d19992
Compare
|



Before: a setting of the wrong type in
cchk.tomleither crashed or was silently misread.message_pattern = 5printedError: 'int' object has no attribute 'strip'and exited 1, the code a rejected commit gets.subject_max_length = truebecame a limit of 1 character.allow_commit_types = "feat,fix"was iterated letter by letter, sof: ...passed CC001. And when the last-resort handler caught an exception with no text (e.g.MemoryError), it printed a bareError:.After: a non-string
message_pattern,author_name_patternorauthor_email_pattern, or a subject length that is not a whole number, is a configuration error (exit 2) that names the setting. A comma-separated string inallow_commit_types,allow_branch_typesorallow_branch_namesis split the same way--allow-commit-typesandCCHK_ALLOW_COMMIT_TYPESalready split it; any other non-list value, or a list with non-string items, is a configuration error. The last-resort handler prints the exception's type name when its message is empty.Before / after
Before (main):
After (this branch):
Before (main):
After (this branch):
Before (main):
exit=0After (this branch):
How
Two helpers in
rule_builder.py, next to_checked_regex:_string_setting(raisesConfigErrorwithsetting=for a non-string) and_string_list(splits a string on commas likeparse_list, raises for anything else that is not a list of strings). The pattern, length and allowed-types/names builders use them;_build_length_rulenow raises for a value that is set but is a bool or not an int (an unset length still builds no rule, as before; a string such as"50"used to disable the rule silently and now is an error too). The last-resortexcept Exceptioninmain.pyprintsstr(e) or type(e).__name__; its exit code stays 1, since the README defines 2 as "nothing was checked" and that handler can also be reached after checks have run. Tests added intests/rule_builder_test.py(TestWrongTypeSettings) andtests/main_test.py(exit 2 formessage_pattern = 5, and the handler's message with and without text). No existing test asserted the old behaviour.Not changed here:
ignore_authorsas a string is still not split (the engine reads it directly and matches within); that can be a follow-up if wanted.Users see new exit-2 errors for these configs, so the configuration page on commit-check.com may need a note after release.