Skip to content

fix(ci): pin UTF-8 when decoding clang-query output - #3747

Merged
zackees merged 1 commit into
masterfrom
fix/clang-query-utf8-decode
Jul 28, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/clang-query-utf8-decode

Conversation

@zackees

@zackees zackees commented Jul 28, 2026 •

Copy link
Copy Markdown
Member

Problem

ci/tools/check_array_params.py and ci/tools/check_noexcept.py both call:

subprocess.run([...], capture_output=True, text=True, ...)

text=True with no encoding decodes using the locale codec. On Windows that is cp1252, and clang-query emits UTF-8. The decode raises inside the subprocess reader thread, which does not propagate as a clean error — it leaves result.stdout as None, so the next line fails:

UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 85530
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

Impact

Both AST ratchets crash instead of running for Windows contributors:

  • the decayed-array-parameter ratchet (array_param_baseline.txt)
  • the FL_NO_EXCEPT ratchet

So new violations of either rule aren't caught locally and only surface later in CI.

Fix

Pin encoding="utf-8" with errors="replace" at both call sites. errors="replace" means a stray byte degrades to a replacement character inside a diagnostic string rather than taking down the whole check — these are error-reporting paths, so failing to decode one byte should never be fatal.

Validation

uv run python ci/tools/check_array_params.py --scope all goes from the traceback above to completing normally:

NOTE: 2 stale array parameter baseline entrie(s) can be pruned.
All non-baselined owned src functions avoid decayed array parameters.
Known baseline entries: 34

bash lint green (ruff + ty pass).

Note: I did not act on that "2 stale entries" hint. Regenerating the baseline locally drops two entries in files this branch never touched, which suggests the local run under-detects relative to CI rather than that the entries are genuinely dead. Pruning it belongs in a separate change made from a run that's trusted to be complete.

Found while verifying a signature change on #3746.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved Windows compatibility for code-quality checks by ensuring tool output is decoded consistently.
    • Prevented locale-related decoding errors that could cause checks to fail or produce incorrect results.

`subprocess.run(..., text=True)` without an explicit encoding decodes with
the locale codec. On Windows that is cp1252, so clang-query's UTF-8 output
raises UnicodeDecodeError inside the subprocess reader thread. The exception
does not propagate directly -- it leaves `result.stdout` as None, and the
caller then dies on `None + str`:

    TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

Net effect: the decayed-array-parameter ratchet and the FL_NO_EXCEPT ratchet
both crash instead of running for Windows contributors, so violations are
only caught later in CI.

Pin encoding="utf-8" with errors="replace" so a stray byte degrades to a
replacement character in a diagnostic rather than taking down the check.

Found while verifying a signature change against check_array_params.py.

Co-Authored-By: Claude <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 28, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: dcdcb980-1855-4849-b90b-6c8a437a5686

📥 Commits

Reviewing files that changed from the base of the PR and between fab494d and 6c32ed9.

📒 Files selected for processing (2)
  • ci/tools/check_array_params.py
  • ci/tools/check_noexcept.py

📝 Walkthrough

Walkthrough

Clang-query subprocess calls in two CI tools now explicitly decode output as UTF-8 and replace invalid bytes, avoiding locale-dependent decoding failures without changing subsequent parsing or error handling.

Changes

Clang-query decoding

Layer / File(s) Summary
Explicit UTF-8 subprocess decoding
ci/tools/check_array_params.py, ci/tools/check_noexcept.py
Both clang-query invocations specify UTF-8 decoding with replacement for invalid bytes while preserving existing output handling.

Estimated code review effort: 2 (Simple) | ~5 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: forcing UTF-8 decoding for clang-query output in CI checks.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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 fix/clang-query-utf8-decode

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.

@zackees
zackees merged commit 074088b into master Jul 28, 2026
13 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jul 28, 2026
zackees added a commit that referenced this pull request Jul 28, 2026
Found while checking PR #3749's new test against the ratchet. Running

    subprocess_capture_checker.py ci/tests/some_file.py

reported "239 baselined subprocess usage(s) are now gone" -- because the
improvement check compared the whole baseline against a single file's
findings. Every entry for a file that was simply not examined counted as
fixed.

That message is wrong on its own, but the dangerous part is the action it
invites: adding --update-baseline to that same narrow command rewrote the
baseline from just that file, silently deleting the other 128 entries and
turning the ratchet off across the repo. The next raw Popen would have gone
in unnoticed.

Both halves now key off the set of files actually scanned:

- --update-baseline merges instead of overwriting, keeping entries for
  unscanned files verbatim. A file that genuinely improved still shrinks or
  drops out, so the ratchet can still be tightened incrementally.
- The "now gone" note only counts entries for files this run looked at.

Also drops the two check_array_params/check_noexcept SRC004 entries that
#3747 resolved -- the baseline was generated just before that merged, so it
was stale by exactly those two.

Tests cover the narrow-update case, the misleading note, that a rescanned
file can still shrink, and that a genuinely new violation still fails. The
first three fail against the previous implementation.

Validated: 556 passed / 39 skipped in ci/tests, lint green.

Co-Authored-By: Claude <[email protected]>
@zackees
zackees deleted the fix/clang-query-utf8-decode branch August 21, 2026 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant