Fix Response.data normalisation in parse_message() too

The previous commit only fixed Response.from_json(), but the serial
client's read loop uses parse_message() which constructs Response
directly. Apply the same string-to-dict normalisation there.
This commit is contained in:
Ryan Malloy 2026-02-02 15:58:20 -07:00
parent ea22f2f9db
commit 82cd0e5c9d

View File

@ -207,11 +207,14 @@ def parse_message(line: str) -> Command | Response | Event:
) )
if msg_type == MsgType.RESP: if msg_type == MsgType.RESP:
raw_data = obj.get("data", {})
if isinstance(raw_data, str):
raw_data = {"error": raw_data}
return Response( return Response(
type=MsgType.RESP, type=MsgType.RESP,
id=obj["id"], id=obj["id"],
status=Status(obj["status"]), status=Status(obj["status"]),
data=obj.get("data", {}), data=raw_data if isinstance(raw_data, dict) else {},
) )
if msg_type == MsgType.EVENT: if msg_type == MsgType.EVENT: