Skip to content

fix: refuse config values of the wrong type - #624

Merged
shenxianpeng merged 4 commits into
mainfrom
fix/config-value-types
Oct 18, 2026
Merged

shenxianpeng merged 4 commits into
mainfrom
fix/config-value-types

Conversation

@shenxianpeng

@shenxianpeng shenxianpeng commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Before: a setting of the wrong type in cchk.toml either crashed or was silently misread. message_pattern = 5 printed Error: 'int' object has no attribute 'strip' and exited 1, the code a rejected commit gets. subject_max_length = true became a limit of 1 character. allow_commit_types = "feat,fix" was iterated letter by letter, so f: ... passed CC001. And when the last-resort handler caught an exception with no text (e.g. MemoryError), it printed a bare Error: .

After: a non-string message_pattern, author_name_pattern or author_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 in allow_commit_types, allow_branch_types or allow_branch_names is split the same way --allow-commit-types and CCHK_ALLOW_COMMIT_TYPES already 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

$ printf '[commit]\nmessage_pattern = 5\n' > cchk.toml
$ echo "feat: x" | python -m commit_check.main -m; echo "exit=$?"

Before (main):

Error: 'int' object has no attribute 'strip'
exit=1

After (this branch):

Error: [commit] message_pattern must be a string, got 5
exit=2
$ printf '[commit]\nallow_commit_types = "feat,fix"\nsubject_max_length = true\n' > cchk.toml
$ echo "f: x" | python -m commit_check.main -m --compact; echo "exit=$?"

Before (main):

[FAIL] CC004 subject-max-length: f: x
[FAIL] CC005 subject-min-length: f: x
exit=1

After (this branch):

Error: [commit] subject_max_length must be a whole number, got True
exit=2
$ printf '[commit]\nallow_commit_types = "feat,fix"\n' > cchk.toml
$ echo "f: add the thing" | python -m commit_check.main -m --compact; echo "exit=$?"

Before (main):

exit=0

After (this branch):

[FAIL] CC001 message: f: add the thing
exit=1

How

Two helpers in rule_builder.py, next to _checked_regex: _string_setting (raises ConfigError with setting= for a non-string) and _string_list (splits a string on commas like parse_list, raises for anything else that is not a list of strings). The pattern, length and allowed-types/names builders use them; _build_length_rule now 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-resort except Exception in main.py prints str(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 in tests/rule_builder_test.py (TestWrongTypeSettings) and tests/main_test.py (exit 2 for message_pattern = 5, and the handler's message with and without text). No existing test asserted the old behaviour.

Not changed here: ignore_authors as a string is still not split (the engine reads it directly and matches with in); 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.

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.
@shenxianpeng
shenxianpeng requested a review from a team as a code owner October 15, 2026 19:48
@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4c47b3e6-0138-4137-9e9d-7003a121e922
📥 Commits

Reviewing files that changed from the base of the PR and between 4791607 and 03dc619.

📒 Files selected for processing: 4
  • commit_check/main.py
  • commit_check/rule_builder.py
  • tests/main_test.py
  • tests/rule_builder_test.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@shenxianpeng shenxianpeng self-assigned this Oct 15, 2026
@codecov

codecov Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (4791607) to head (03dc619).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codspeed

codspeed Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

⚠️ 128 benchmarks spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

✅ 645 untouched benchmarks
⏩ 126 skipped benchmarks1


Comparing fix/config-value-types (03dc619) with main (4791607)

Open in CodSpeed

Footnotes

  1. 126 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

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.
@github-actions github-actions Bot added the bug Something isn't working label Oct 15, 2026
@shenxianpeng
shenxianpeng force-pushed the fix/config-value-types branch from e606596 to 8d19992 Compare October 18, 2026 06:02
@sonarqubecloud

Copy link
Copy Markdown

@shenxianpeng
shenxianpeng merged commit e4e31dc into main Oct 18, 2026
33 checks passed
@shenxianpeng
shenxianpeng deleted the fix/config-value-types branch October 18, 2026 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant