Skip to content

Commit

Permalink
Fix: packet parse exception text (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
nanato12 authored Jan 10, 2025
1 parent 3c59cfb commit 59c12dc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion line_works/mqtt/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ async def __handle_binary_message(self, message: bytes) -> None:
elif p.unique_id:
self._unique_ids.append(p.unique_id)
except PacketParseException as e:
logger.error("packet parse error", exc_info=e)
logger.debug("packet parse error", exc_info=e)

logger.debug(f"{packet=}")

Expand Down
7 changes: 6 additions & 1 deletion line_works/mqtt/models/packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ def publish_payload(self) -> dict[str, Any]:
qos = (self.flags & 0x06) >> 1
if qos > 0:
if len(self.raw_payload) < pos + 2:
raise PacketParseException("Packet too short for QoS > 0")
raise PacketParseException(
"Packet too short for QoS > 0: "
f"expected at least {pos + 2} bytes, "
f"but got {len(self.raw_payload)} bytes. "
f"raw_payload: {self.raw_payload.hex()}"
)
pos += 2

payload = self.raw_payload[pos:].decode("utf-8")
Expand Down

0 comments on commit 59c12dc

Please sign in to comment.