[client] stream_measurements: skip malformed frames instead of raising bare KeyError (kills reconnect loop) #179

Closed
opened 2026-10-27 11:31:54 +00:00 by mat · 0 comments
Owner

Two bare indexing sites raise KeyError on a malformed frame:

  • Measurement.from_measure reads measure["value"], measure["capacityId"], measure["measureKind"] (_streaming.py:86-89);
  • the frame loop reads payload["gatewayUid"] (_streaming.py:157).

In reconnect mode, a malformed frame therefore escapes the generator as a bare KeyError, killing the reconnect loop instead of surfacing as ComwattStreamingError or being skipped. A single glitched frame takes down a stream meant to survive.

Fix: tolerate malformed frames — skip anything that does not parse (missing keys / wrong shapes), keeping the loop alive; only transport-level failures should raise. Silence + survival is the minimum bar; a debug hook surfacing skipped frames is optional.

Done when: a malformed measures frame is skipped and subsequent valid frames still yield — covered by a test feeding a bad frame mid-stream in reconnect mode.

Two bare indexing sites raise `KeyError` on a malformed frame: - `Measurement.from_measure` reads `measure["value"]`, `measure["capacityId"]`, `measure["measureKind"]` (`_streaming.py:86-89`); - the frame loop reads `payload["gatewayUid"]` (`_streaming.py:157`). In reconnect mode, a malformed frame therefore escapes the generator as a bare `KeyError`, killing the reconnect loop instead of surfacing as `ComwattStreamingError` or being skipped. A single glitched frame takes down a stream meant to survive. **Fix:** tolerate malformed frames — skip anything that does not parse (missing keys / wrong shapes), keeping the loop alive; only transport-level failures should raise. Silence + survival is the minimum bar; a debug hook surfacing skipped frames is optional. **Done when:** a malformed measures frame is skipped and subsequent valid frames still yield — covered by a test feeding a bad frame mid-stream in reconnect mode.
mat closed this issue 2026-10-27 14:36:26 +00:00
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
mat/python-comwatt-client#179
No description provided.