Skip to content

fix(fled): let the compiler check the pixel-format mapping (#4034 D1) - #4349

Merged
zackees merged 1 commit into
masterfrom
fix/4034-exhaustive-pixel-format-map
Sep 11, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/4034-exhaustive-pixel-format-map

Conversation

@zackees

@zackees zackees commented Sep 11, 2026 •

Copy link
Copy Markdown
Member

#4034's D1 asks callers to use "checked, explicit mapping rather than casting between enums" for fl::fled::PixelFormat → fl::PixelFormat.

toPixelStorage() did exactly that — and then swept four of the six wire formats into default: return false. The mapping was checked; nothing checked that the mapping was complete.

What changes

Gray8, Rgba8, Rgbw8 and Rgb565Le are listed explicitly. Two consequences:

  • they read as known and unmapped rather than possibly forgotten — bytesPerLed already knows all six, so the asymmetry was real and undocumented
  • a seventh wire format becomes a compile error naming this function, instead of a silent false discovered at playback

Verified

Adding a probe enumerator:

error: enumeration value 'MutProbe' not handled in switch [-Werror,-Wswitch]
  src/fl/fled/detail/pixel_format.cpp.hpp:24

Before the change, the same probe compiled clean.

What deliberately keeps its default

bytesPerLed() takes a raw wire byte, not the enum, so it must answer for values that are not enumerators at all. Its default: return 0 is doing real work and stays.

Why this is worth a PR on its own

Same lesson as two earlier ones this cycle, from opposite directions:

This is the third: a mapping that was correct today and had no way to stay correct. The fix is to let the compiler hold it rather than a reader.

bash test --cpp --clean: 304/304 unit, 84/84 examples. bash lint clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9

Summary by CodeRabbit

  • Refactor
    • Explicitly handles supported wire formats when determining pixel storage.
    • Future unsupported wire formats are more likely to be identified during compilation rather than silently at runtime.

D1 asks callers to use "checked, explicit mapping rather than casting between
enums" for fl::fled::PixelFormat -> fl::PixelFormat. toPixelStorage() did
that, and then swept four of the six wire formats into `default: return
false`. The mapping was checked; nothing checked the mapping was complete.

Gray8, Rgba8, Rgbw8 and Rgb565Le are now listed explicitly, so they read as
known-and-unmapped rather than possibly-forgotten, and a seventh wire format
is a compile error naming this function instead of a silent false found at
playback.

Verified: adding a probe enumerator gives
  error: enumeration value 'MutProbe' not handled in switch [-Werror,-Wswitch]
against src/fl/fled/detail/pixel_format.cpp.hpp:24. Before, it compiled.

bytesPerLed() keeps its default deliberately -- it takes a raw wire byte, not
the enum, so it must answer for values that are not enumerators at all.

Same lesson as #4340, where a SourceKind switch with no default caught an
added source at compile time, and #4341, where three guard lists that could
drift silently were made to check each other.

bash test --cpp --clean: 304/304 unit, 84/84 examples. bash lint clean.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9
@coderabbitai

coderabbitai Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Review Change StackReview 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: Advanced

Run ID: 6de52998-ba32-413f-8eb7-66764a4e3f42

📥 Commits

Reviewing files that changed from the base of the PR and between 574ef41 and 5ff6790.

📒 Files selected for processing (1)
  • src/fl/fled/detail/pixel_format.cpp.hpp

Included review availability: Your plan provides up to 8 included reviews per hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

toPixelStorage now uses explicit cases for the four non-storage wire formats. The default branch was removed so an unhandled future wire format produces a compile-time diagnostic.

Changes

Pixel format handling

Layer / File(s) Summary
Explicit wire format cases
src/fl/fled/detail/pixel_format.cpp.hpp
toPixelStorage lists Gray8, Rgba8, Rgbw8, and Rgb565Le as explicit cases that return false. The default branch was removed. A comment documents the compile-time detection intent for future formats.

Priority: ⬇️ Low

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

Merge Risk: ⚪ Minimal · up to 5ff67

The change preserves current conversion behavior while making future pixel-format additions visible at compile time.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: removing the default mapping path so the compiler checks pixel-format handling.
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/4034-exhaustive-pixel-format-map

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 06d66ad into master Sep 11, 2026
27 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Sep 11, 2026
@zackees
zackees deleted the fix/4034-exhaustive-pixel-format-map branch November 5, 2026 05:52
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