Skip to content

fix(ci-iwyu): fail fast on missing IWYU mappings, handle missing uv, reword --fix note - #2338

Merged
zackees merged 1 commit into
masterfrom
feat/iwyu-followup-2331
Apr 19, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/iwyu-followup-2331

Conversation

@zackees

@zackees zackees commented Apr 19, 2026 •

Copy link
Copy Markdown
Member

Summary

Follow-up to #2331 — applies the three CodeRabbit findings from the final review pass that didn't make it into the merge.

  • 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.
  • 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.
  • Reword the --fix-unsupported note. Dropping the result_code == 0 guard 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.py passes
  • uv run python ci/ci-iwyu.py esp32c2 still exits 0 on a board that actually has both .imp files + uv (no regression)
  • Manually delete ci/iwyu/fastled.imp → confirm the new error fires and returns 1

Related

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Enhanced error handling in CI checks for missing dependencies and failed processes.
    • Improved error messaging to provide clearer feedback when build tools fail to initialize.

…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]>
@coderabbitai

coderabbitai Bot commented Apr 19, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The 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

Cohort / File(s) Summary
IWYU Script Error Handling
ci/ci-iwyu.py
Added missing mapping file error reporting (stderr + return code 1); added FileNotFoundError handling for subprocess invocation; updated fbuild --fix mode messaging.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 A rabbit hops through errors with care,
No more silent fails in the CI air!
Mapping files checked, subprocess trapped,
When things go wrong, we're properly mapped. 📋✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately summarizes the three main changes: failing fast on missing IWYU mappings, handling missing uv, and rewording the --fix note.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/iwyu-followup-2331

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.

@coderabbitai coderabbitai Bot 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.

🧹 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.imp files 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_args

Then 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 1

As 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

📥 Commits

Reviewing files that changed from the base of the PR and between 89187bf and a493939.

📒 Files selected for processing (1)
  • ci/ci-iwyu.py

@zackees
zackees merged commit 4c9eca4 into master Apr 19, 2026
50 of 80 checks passed
@zackees
zackees deleted the feat/iwyu-followup-2331 branch May 30, 2026 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant