From afbae06520645b6a2a87bbef32234e1e6b1790a7 Mon Sep 17 00:00:00 2001 From: thephez Date: Thu, 7 Mar 2024 15:25:26 -0500 Subject: [PATCH] fix: check if message can be handled before attempting to deserialize Co-authored-by: UdjinM6 --- contrib/message-capture/message-capture-parser.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/contrib/message-capture/message-capture-parser.py b/contrib/message-capture/message-capture-parser.py index 33759ee71377a..b416c11302bb6 100755 --- a/contrib/message-capture/message-capture-parser.py +++ b/contrib/message-capture/message-capture-parser.py @@ -122,8 +122,8 @@ def process_file(path: str, messages: List[Any], recv: bool, progress_bar: Optio msg_ser = BytesIO(f_in.read(length)) # Determine message type - if msgtype not in MESSAGEMAP: - # Unrecognized message type + if msgtype not in MESSAGEMAP or MESSAGEMAP[msgtype] is None: + # Unrecognized or unhandled message type try: msgtype_tmp = msgtype.decode() if not msgtype_tmp.isprintable(): @@ -131,10 +131,11 @@ def process_file(path: str, messages: List[Any], recv: bool, progress_bar: Optio msg_dict["msgtype"] = msgtype_tmp except UnicodeDecodeError: msg_dict["msgtype"] = "UNREADABLE" + err_str = "Unrecognized" if msgtype not in MESSAGEMAP else "Unhandled" msg_dict["body"] = msg_ser.read().hex() - msg_dict["error"] = "Unrecognized message type." + msg_dict["error"] = f"{err_str} message type" messages.append(msg_dict) - print(f"WARNING - Unrecognized message type {msgtype} in {path}", file=sys.stderr) + print(f"WARNING - {msg_dict['error']} {msgtype} in {path}", file=sys.stderr) continue # Deserialize the message