Repository navigation
Fix: Prevent TypeError in ws_poster when image is None - #961
Merged
Merged
Conversation
Gracefully handle cases where the camera image cannot be fetched (evaluates to None). Previously, attempting to log `len(image)` caused an unhandled TypeError, resulting in a 500 Internal Server Error.
|
Confirming this fix. I get the same I carry the identical guard in production: _LOGGER.debug(f"webrtc image_entity: {image_entity} - {len(image) if image else 0}")
For my own use, to run my camera fleet, I developed a fully-compatible drop-in fork
(https://github.com/fuzzybear62/webrtc) that — among other things — includes this fix.
Fair warning: I maintain it for my own multi-camera fleet, so it's provided as-is /
best-effort, not a supported product. |
davidcoulson
added a commit
to davidcoulson/WebRTC
that referenced
this pull request
Sep 11, 2026
Cherry-picked 5 unmerged bug-fix PRs from upstream AlexxIT/WebRTC (stale since 2025-11-26): - PR AlexxIT#938 (vinnybad): fix InvalidStateError crash in MSE updateend handler - PR AlexxIT#956 (joyjit): reject expired/invalid stream authSig with 403 instead of 401, avoiding HA's own login-ban middleware locking out the household - PR AlexxIT#961 (skircr115): prevent TypeError in ws_poster when image is None - PR AlexxIT#942 (mayerwin): fix media_player.play_media via go2rtc /api/ffmpeg - PR AlexxIT#951 (daveyijzermans): only fall back to muted playback on NotAllowedError, not on every transient play() rejection
davidcoulson
added a commit
to davidcoulson/WebRTC
that referenced
this pull request
Sep 11, 2026
Correctness: - ws_poster/_get_image_from_entity_id: the cherry-picked PR AlexxIT#961 fix only silenced the crash in the debug log line, but still returned HTTP 200 with an empty body when an image entity has no image. Now raises HTTPNotFound so callers see a real failure instead of a false success. Also switched the bare Exception in _get_image_from_entity_id to HTTPNotFound for the same reason. - media_player.py: replaced assert r.ok (stripped under python -O, no user-facing message) with HomeAssistantError including the status code, in both async_play_media and async_media_stop. - media_player.py async_update: a bare except clause was catching asyncio.CancelledError (a BaseException) along with everything else, which can interfere with clean task cancellation. Narrowed to the actual expected failure modes (ClientError, TimeoutError, KeyError, ValueError) and logs at debug level instead of silently swallowing. - config_flow.py: the go2rtc.yaml write was a blocking file write inside an async config flow step; moved to hass.async_add_executor_job. - __init__.py: HomeAssistant was imported from homeassistant.components.binary_sensor (fragile, unrelated module); now imported from homeassistant.core directly. HA design-language alignment: - Added strings.json as the canonical English source (was previously only in translations/en.json, which hassfest flags as outdated). - Added a visual (GUI) card editor via ha-form + entity/text/boolean selectors, registered through getConfigElement(), covering the common config fields (entity, url, title, mode, muted, background, ui). Advanced options (streams array, digital PTZ, etc.) remain available through the YAML editor, which Hass still offers alongside this one.
Owner
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes a bug in
ws_posterwhere an unhandledTypeErroris thrown if the camera entity fails to provide an image.Motivation and Context
Currently, if
imageevaluates toNone, the debug logger attempts to executelen(image). This crashes the HTTP request and dumps the following traceback into the Home Assistant logs:TypeError: object of type 'NoneType' has no len()This prevents a 500 Internal Server Error and stops log spam for users whose cameras occasionally drop offline or fail to serve a thumbnail.
Changes
_LOGGER.debugcall inws_posterto safely check ifimageexists before checking its length.