Skip to content

Fix: Prevent TypeError in ws_poster when image is None - #961

Open
skircr115 wants to merge 1 commit into
AlexxIT:masterfrom
skircr115:master
Open

Fix: Prevent TypeError in ws_poster when image is None#961
skircr115 wants to merge 1 commit into
AlexxIT:masterfrom
skircr115:master

Conversation

@skircr115

Copy link
Copy Markdown

Description

This PR fixes a bug in ws_poster where an unhandled TypeError is thrown if the camera entity fails to provide an image.

Motivation and Context

Currently, if image evaluates to None, the debug logger attempts to execute len(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

  • Updated the _LOGGER.debug call in ws_poster to safely check if image exists before checking its length.

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.
@fuzzybear62

Copy link
Copy Markdown

Confirming this fix. I get the same TypeError: object of type 'NoneType' has no len()
whenever a camera briefly fails to serve a thumbnail, and @skircr115's guard is the right one:
the len(image) in the _LOGGER.debug call has to check that image exists first — otherwise
the debug line itself crashes the request into a 500 and spams the HA log, on what is only a
logging statement.

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) thatamong other thingsincludes 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.

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.

2 participants