Repository navigation
fix(ci-iwyu): fail fast on missing IWYU mappings, handle missing uv, reword --fix note - #2338
Conversation
…d --fix note Three more CodeRabbit findings, all aligned with the project's "no silent fallbacks for critical resources" stance (CLAUDE.md: "Find root causes. No temporary fixes. Senior developer standards.") — reconsidered from the prior round: 1. fail-fast on missing fastled.imp / stdlib.imp. Silently skipping either mapping changes IWYU's answers while still returning a passing status — a classic silent-correctness bug. Absence is now a hard error with the expected path in the message. 2. Handle FileNotFoundError from subprocess.run when `uv` is missing. check_iwyu_available() can succeed via the system IWYU path, so it's legitimately possible to reach this code without `uv` installed. Convert the cryptic traceback into a clear CI diagnostic. 3. Reword the --fix-unsupported note. Dropping the prior `result_code == 0` guard made the warning unconditional, which turned the old "violations were reported but not auto-fixed" into a lie when IWYU exits clean. Change to "IWYU was run in report-only mode — no changes were auto-fixed" so the note stays accurate regardless of result. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
📝 WalkthroughWalkthroughThe PR adds defensive error handling to the IWYU CI script: it now fails with stderr output when required mapping files are missing, catches FileNotFoundError for subprocess invocation, and clarifies error messaging for the --fix behavior. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
ci/ci-iwyu.py (1)
497-506: Apply the required-mapping fail-fast behavior to PlatformIO mode too.Line 500 now fails fast for fbuild, but lines 587-590 still silently skip the same required
fastled.imp/stdlib.impfiles in the PlatformIO path. That keeps the old “success with changed IWYU answers” failure mode for non-fbuild boards.♻️ Proposed consolidation
+def _required_iwyu_mapping_args(project_root: Path, xiwyu: bool) -> list[str]: + mapping_args: list[str] = [] + for name in ("fastled.imp", "stdlib.imp"): + p = project_root / "ci" / "iwyu" / name + if not p.is_file(): + raise FileNotFoundError(f"required IWYU mapping file not found: {p}") + if xiwyu: + mapping_args.extend(["-Xiwyu", f"--mapping_file={p}"]) + else: + mapping_args.extend(["--mapping_file", str(p)]) + return mapping_argsThen use it in both callers:
- mapping_args: list[str] = [] - for name in ("fastled.imp", "stdlib.imp"): - p = project_root / "ci" / "iwyu" / name - if not p.exists(): - print( - f"ERROR: required IWYU mapping file not found: {p}", - file=sys.stderr, - ) - return 1 - mapping_args.extend(["-Xiwyu", f"--mapping_file={p}"]) + try: + mapping_args = _required_iwyu_mapping_args(project_root, xiwyu=True) + except FileNotFoundError as e: + print(f"ERROR: {e}", file=sys.stderr) + return 1- for name in ("fastled.imp", "stdlib.imp"): - p = project_root / "ci" / "iwyu" / name - if p.exists(): - mapping_args.extend(["--mapping_file", str(p)]) + try: + mapping_args = _required_iwyu_mapping_args(project_root, xiwyu=False) + except FileNotFoundError as e: + print(f"ERROR: {e}", file=sys.stderr) + return 1As per coding guidelines, “Never use silent fallbacks for missing critical resources - always fail fast with descriptive errors”.
Also applies to: 587-590
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ci/ci-iwyu.py` around lines 497 - 506, The code currently checks for required IWYU mapping files and fails fast for the fbuild path using mapping_args but the PlatformIO branch still silently skips missing files; modify the PlatformIO logic to perform the same existence checks and fail fast with a descriptive stderr message and non-zero return when either "fastled.imp" or "stdlib.imp" under project_root / "ci" / "iwyu" is missing. You can factor the check into a small helper (e.g., validate_mapping_files or reuse mapping_args construction) and call it from both the fbuild and PlatformIO callers so both code paths use the same fail-fast behavior and error text.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@ci/ci-iwyu.py`:
- Around line 497-506: The code currently checks for required IWYU mapping files
and fails fast for the fbuild path using mapping_args but the PlatformIO branch
still silently skips missing files; modify the PlatformIO logic to perform the
same existence checks and fail fast with a descriptive stderr message and
non-zero return when either "fastled.imp" or "stdlib.imp" under project_root /
"ci" / "iwyu" is missing. You can factor the check into a small helper (e.g.,
validate_mapping_files or reuse mapping_args construction) and call it from both
the fbuild and PlatformIO callers so both code paths use the same fail-fast
behavior and error text.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 978b6fcf-34f1-4479-bcfe-43fa8bcbeec0
📒 Files selected for processing (1)
ci/ci-iwyu.py
Summary
Follow-up to #2331 — applies the three CodeRabbit findings from the final review pass that didn't make it into the merge.
fastled.imp/stdlib.imp. Silently skipping either mapping changes IWYU's answers while still returning a passing status — a classic silent-correctness bug. Absence is now a hard error with the expected path in the message.FileNotFoundErrorfromsubprocess.runwhenuvis missing.check_iwyu_available()can succeed via the system IWYU path, so it's legitimately possible to reach this code withoutuvinstalled. Convert the cryptic traceback into a clear CI diagnostic.--fix-unsupported note. Dropping theresult_code == 0guard in refactor(ci): decouple IWYU + cppcheck from PIO project tree (#2303) #2331 made the warning unconditional, which turned the old "violations were reported but not auto-fixed" into a lie when IWYU exits clean. Change to "IWYU was run in report-only mode — no changes were auto-fixed" so the note stays accurate regardless of result.All three align with CLAUDE.md's "find root causes, no temporary fixes — senior developer standards" stance.
Test plan
bash lint ci/ci-iwyu.pypassesuv run python ci/ci-iwyu.py esp32c2still exits 0 on a board that actually has both .imp files + uv (no regression)ci/iwyu/fastled.imp→ confirm the new error fires and returns 1Related
🤖 Generated with Claude Code
Summary by CodeRabbit