Skip to content

Map Any Unexpected Compile Lint Failure to Exit 2 - #267

Merged
ptr727 merged 3 commits into
developfrom
feature/lint-database-errors
Oct 25, 2026
Merged

ptr727 merged 3 commits into
developfrom
feature/lint-database-errors

Conversation

@ptr727

@ptr727 ptr727 commented Oct 25, 2026

Copy link
Copy Markdown
Owner

Fixes a finding the hosted review raised on the develop -> main promotion pull request: an unexpected failure in the compile lint escaped as a Python exception, which exits 1, the code the lint documents for a finding.

  • main maps any exception other than the lint's own LintError to exit 2, and prints its traceback first, since such a failure is a bug in the lint. This closes the class at every site, including a truncated compile database, an unreadable source, and an unbalanced quote in a compile command.
  • load_compile_database still turns an unreadable file or invalid JSON into a LintError, since an interrupted build can leave the file truncated.

Unit tests, ruff, pyright and the prose gate pass. The new tests fail without the change.

🤖 Generated with Claude Code

@ptr727 ptr727 added the comments Permits the comment lines the pull request adds or edits, which the prose gate otherwise refuses label Oct 25, 2026
Copilot AI lite review requested due to automatic review settings October 25, 2026 17:18
@ptr727

ptr727 commented Oct 25, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head eaaac299a9bbaba2a80165ba77621a353b005439, the content this pull request carries at that commit against develop, and it recorded 0 findings.

@coderabbitai

coderabbitai Bot commented Oct 25, 2026

Copy link
Copy Markdown

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 13 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
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: b02d795e-f7b4-4eef-b28d-ba761fbca375
Commits

Reviewing files that changed from the base of the PR and between 59c44d4 and eaaac29.

Files selected for processing: 2
  • tests/compile_lint/test_lint.py
  • tools/compile-lint/src/compile_lint/lint.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.

@codecov

codecov Bot commented Oct 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.61%. Comparing base (59c44d4) to head (eaaac29).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #267      +/-   ##
===========================================
+ Coverage    84.36%   84.61%   +0.25%     
===========================================
  Files            3        3              
  Lines          614      624      +10     
===========================================
+ Hits           518      528      +10     
  Misses          96       96              
Flag Coverage Δ
python-3.13 84.61% <100.00%> (+0.25%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

@ptr727
ptr727 merged commit edff1c7 into develop Oct 25, 2026
38 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The exit-code fix is sound, but the catch-all comment is inaccurate and the new tests leave the unreadable-file and invalid-JSON paths unverified.

4 open issues
What changed in this PR

This PR closes a gap in the compile lint. An unexpected failure used to escape as a Python exception, which exits 1. Exit 1 means a finding, so a crash looked like a lint result. Now main catches any non-LintError exception, prints its traceback, and exits 2. load_compile_database also turns an unreadable or invalid-JSON database into a LintError, since an interrupted build can leave the file truncated.

Changes:

  • main now delegates to a new run function. A LintError prints a message and exits 2. Any other exception prints its traceback and exits 2.
  • load_compile_database wraps read and parse errors in a LintError with a "cannot read the compile database" message.
  • New tests check that malformed databases exit 2 and that an unexpected failure keeps its traceback.
File Description
tools/​compile-lint/​src/​compile_lint/​lint.py Adds the catch-all exit-2 path in main, moves the run body into run, and makes the compile database read raise LintError.
tests/​compile_lint/​test_lint.py Adds tests for malformed compile databases and for the traceback on an unexpected failure.

Review effort: Lite

print(f"compile-lint: {error}", file=sys.stderr)
return 2
except Exception as error: # noqa: BLE001
# Any other failure is a bug in the lint, so keep its stack, and never exit 1, a finding.
Comment on lines +542 to +547
# Invalid JSON is caught where it is read, and the other shapes by main's catch-all.
@pytest.mark.parametrize("content", ["{not json", '{"directory": "/x"}', '[{"file": "a.cpp"}]'])
def test_a_malformed_compile_database_is_a_failure_to_run(tmp_path: Path, content: str) -> None:
root, build = write_build(tmp_path, "")
(build / "build" / "compile_commands.json").write_text(content)
assert main(["--config-root", str(root), str(build)]) == 2
Comment on lines +216 to +218
except (OSError, ValueError) as error:
# An interrupted build can leave the file truncated.
raise LintError(f"cannot read the compile database {path}: {error}") from error
except LintError as error:
print(f"compile-lint: {error}", file=sys.stderr)
return 2
except Exception as error: # noqa: BLE001
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comments Permits the comment lines the pull request adds or edits, which the prose gate otherwise refuses

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants