Fix: Prevent TypeError in ws_poster when image is None - #961
Open
skircr115 wants to merge 1 commit into
Open
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. |
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.