Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: packet parse exception text #29

Merged
merged 4 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading