fix: handle missing customizations key to prevent MediaPlayerThread crash#26
fix: handle missing customizations key to prevent MediaPlayerThread crash#26seffyroff wants to merge 1 commit into
Conversation
Using bare dict subscript raises KeyError when the 'customizations' key is absent from the action's settings (the default state for a newly configured ShowText or similar action). This exception propagates into MediaPlayerThread, killing it — which silently stops all button rendering on the deck while button presses continue to work. Replace the bare subscript with .get(..., []) so a missing key is treated as an empty list rather than a crash.
|
Hi, could you show me a crash log and a step-by-step guide on how to recreate the issue? I have not had an error with that key in the dict missing. Also, the current way of access is intentional because I want missing keys to throw an error as this should not happen - they should be initialized to not be missing. |
|
Hi, thanks for looking at this. Here's the crash log and the root cause analysis — I think there's a schema migration gap rather than the key being reliably initialised. Crash logThe action is a Why the key is absentThe initialisation in if not self._action.get_settings().get(text_const.SETTING_TEXT):
settings[text_const.SETTING_TEXT] = DEFAULT_SETTINGS.copy()For any action that was already configured with an entity before the Suggested fixA if not self._action.get_settings().get(text_const.SETTING_TEXT):
settings = self._action.get_settings()
settings[text_const.SETTING_TEXT] = DEFAULT_SETTINGS.copy()
self._action.set_settings(settings)
# Back-fill any keys added to DEFAULT_SETTINGS after initial save
settings = self._action.get_settings()
for key, default in DEFAULT_SETTINGS.items():
settings[text_const.SETTING_TEXT].setdefault(key, default)
self._action.set_settings(settings)Or more simply, just ensure settings[text_const.SETTING_TEXT].setdefault(customization_const.SETTING_CUSTOMIZATIONS, [])The same pattern likely applies to Happy to update this PR to fix the root cause in |
Could you please detail the steps you are doing to reproduce the issue?
The |
What
get_customizations()inCustomizationSettingsused a bare dict subscript to read thecustomizationskey:When the
customizationskey is absent — which is the default state for any newly configuredShowTextor other customization-based action — this raises aKeyError.Why it matters
The exception isn't caught at the call site. It propagates up through
on_ready()intoMediaPlayerThread, killing the thread. SinceMediaPlayerThreadis responsible for rendering all button images on the deck, every dynamic button stops rendering — clock, CPU, weather, sensor values, all of it. Button presses still work (separate input thread) so the failure mode is subtle: the deck looks static but responds to presses, with no obvious error surfaced to the user.This is reproducible with a fresh
ShowTextaction that has never had a customization added to it.Fix
Replace the bare subscript with
.get(..., [])so a missing key returns an empty list instead of crashing:One-line change. Consistent with how the key would logically be treated if absent (no customizations configured = empty list).
Related
Similar MediaPlayerThread crash pattern to #5 and #19, but a distinct root cause in a different code path.