Skip to content

Conversation

@shenxianpeng
Copy link
Contributor

@shenxianpeng shenxianpeng commented Oct 12, 2025

closes #302

Summary by CodeRabbit

  • New Features
    • Clearer error messages when a specified config file is missing.
  • Bug Fixes
    • Providing a non-existent config path now fails fast with an error and exit code 1.
    • Default config search now runs only when no path is provided.
    • When no default config is found, the app proceeds with an empty configuration instead of erroring.
  • Tests
    • Added and updated tests to validate new error handling and default config behaviors.

@shenxianpeng shenxianpeng requested a review from a team as a code owner October 12, 2025 21:17
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 12, 2025

Walkthrough

The PR changes config-loading semantics: providing a non-existent path now raises FileNotFoundError; default path search runs only when no path is given; absence of any config now returns {}. The CLI now treats a missing specified config as a hard error, printing a message and exiting with code 1. Tests updated accordingly.

Changes

Cohort / File(s) Summary
Config loading semantics
commit_check/config.py
Enforces FileNotFoundError when a provided path_hint is missing; restricts default path probing to cases without path_hint; returns empty dict when no configs are found in defaults.
CLI error handling
commit_check/main.py
Removes internal fallback to {} on missing file; adds top-level handling to print descriptive error and exit(1) when specified config file is missing.
Tests for config behavior
tests/config_test.py
Updates expectations: nonexistent path_hint must raise FileNotFoundError with message; missing defaults yield {}; adjusts invalid path hint tests to the new error message.
Tests for CLI behavior
tests/main_test.py
Adds test ensuring nonexistent config path causes exit code 1 and specific error message; aligns existing tests with new hard-error behavior.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant CLI as main()
  participant Config as load_config()
  participant FS as Filesystem
  participant Stderr as stderr

  User->>CLI: run with --config /path/to/config.toml
  CLI->>Config: load_config(path_hint)
  Config->>FS: check path_hint exists
  alt path exists
    Config-->>CLI: config dict
    CLI->>CLI: proceed with run
  else path missing
    Config-->>CLI: FileNotFoundError("Specified config file not found: ...")
    CLI->>Stderr: print error message
    CLI->>CLI: exit(1)
  end

  User->>CLI: run without --config
  CLI->>Config: load_config(None)
  Config->>FS: search default paths
  alt found
    Config-->>CLI: config dict
  else none found
    Config-->>CLI: {}
  end
  CLI->>CLI: proceed with run
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

I sniffed the configs, twitching my nose,
A path was promised—yet none arose!
Now I thump: “Stop!” with exit one,
No silent hops until it’s done.
But if no hints, I’ll calmly see—
Empty basket, default-free. 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly indicates that the PR adds logic to verify the presence of a user-supplied configuration, which matches the main change of raising an error for missing config and failing early; it concisely describes the key fix.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bugfix/fix-302

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 and usage tips.

@github-actions github-actions bot added the bug Something isn't working label Oct 12, 2025
@sonarqubecloud
Copy link

@codspeed-hq
Copy link

codspeed-hq bot commented Oct 12, 2025

CodSpeed Performance Report

Merging #304 will not alter performance

Comparing bugfix/fix-302 (454b998) with main (5dd8c73)

Summary

✅ 27 untouched
⏩ 85 skipped1

Footnotes

  1. 85 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.

@codecov
Copy link

codecov bot commented Oct 12, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.29%. Comparing base (5dd8c73) to head (454b998).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #304      +/-   ##
==========================================
+ Coverage   86.98%   87.29%   +0.31%     
==========================================
  Files           8        8              
  Lines         684      685       +1     
==========================================
+ Hits          595      598       +3     
+ Misses         89       87       -2     

☔ View full report in Codecov by Sentry.
📢 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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
tests/config_test.py (2)

32-37: Consider escaping regex metacharacters in match pattern.

The test correctly validates the new error behavior. However, the pattern contains . which is a regex metacharacter.

Apply this diff to use a raw string:

-            FileNotFoundError, match="Specified config file not found: nonexistent.toml"
+            FileNotFoundError, match=r"Specified config file not found: nonexistent\.toml"

Based on static analysis hints.


90-99: Consider escaping regex metacharacters in match pattern.

The test correctly validates the new error behavior for invalid path hints. However, the pattern contains . which is a regex metacharacter.

Apply this diff to use a raw string:

-                    match="Specified config file not found: nonexistent.toml",
+                    match=r"Specified config file not found: nonexistent\.toml",

Based on static analysis hints.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5dd8c73 and 454b998.

📒 Files selected for processing (4)
  • commit_check/config.py (1 hunks)
  • commit_check/main.py (2 hunks)
  • tests/config_test.py (2 hunks)
  • tests/main_test.py (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
tests/**

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Ensure tests run via pytest -v and cover commit, branch, author, and CLI behaviors

Files:

  • tests/config_test.py
  • tests/main_test.py
commit_check/main.py

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

commit_check/main.py: Expose CLI flags: --message, --branch, --help, --version, --config, --dry-run; support combining checks
Exit with code 0 on success and 1 on validation failure; emit colorized ASCII-art rejection on errors

Files:

  • commit_check/main.py
🧬 Code graph analysis (3)
tests/config_test.py (1)
commit_check/config.py (1)
  • load_config (21-37)
commit_check/main.py (1)
commit_check/config.py (1)
  • load_config (21-37)
tests/main_test.py (1)
commit_check/main.py (1)
  • main (127-225)
🪛 Ruff (0.13.3)
tests/config_test.py

35-35: Pattern passed to match= contains metacharacters but is neither escaped nor raw

(RUF043)


97-97: Pattern passed to match= contains metacharacters but is neither escaped nor raw

(RUF043)

commit_check/config.py

26-26: Avoid specifying long messages outside the exception class

(TRY003)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (16)
  • GitHub Check: codecov/project
  • GitHub Check: install (3.14, ubuntu-24.04)
  • GitHub Check: install (3.14, macos-latest)
  • GitHub Check: install (3.14, windows-latest)
  • GitHub Check: install (3.13, windows-latest)
  • GitHub Check: install (3.12, ubuntu-24.04)
  • GitHub Check: install (3.13, ubuntu-24.04)
  • GitHub Check: install (3.12, windows-latest)
  • GitHub Check: install (3.10, ubuntu-24.04)
  • GitHub Check: install (3.11, macos-latest)
  • GitHub Check: install (3.9, macos-latest)
  • GitHub Check: install (3.11, windows-latest)
  • GitHub Check: install (3.10, macos-latest)
  • GitHub Check: install (3.10, windows-latest)
  • GitHub Check: install (3.9, windows-latest)
  • GitHub Check: install (3.9, ubuntu-24.04)
🔇 Additional comments (6)
commit_check/main.py (2)

138-139: LGTM!

The config loading now correctly propagates FileNotFoundError when a specified config file doesn't exist, aligning with the PR's objective to treat missing configs as hard errors.


220-222: LGTM!

The FileNotFoundError handler correctly prints the error and exits with code 1, meeting the coding guideline requirement for validation failures.

tests/main_test.py (2)

240-242: LGTM!

The test correctly validates that a non-existent config file results in exit code 1.


280-297: LGTM!

Comprehensive test coverage for the new error handling behavior, verifying both exit code and error message.

commit_check/config.py (1)

21-37: LGTM!

The config loading logic correctly implements the new semantics:

  1. Raises FileNotFoundError for non-existent specified paths
  2. Checks default paths only when no path is provided
  3. Returns empty dict when no config files exist

The error message is descriptive and user-friendly. The static analysis warning (TRY003) can be safely ignored as the message provides essential context.

tests/config_test.py (1)

78-85: LGTM!

The test correctly validates that an empty config dict is returned when no default config files exist.

@shenxianpeng shenxianpeng merged commit 213b6d2 into main Oct 12, 2025
32 checks passed
@shenxianpeng shenxianpeng deleted the bugfix/fix-302 branch October 12, 2025 21:20
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.

check user input config exist or not

2 participants