From 6bab38538039ec5cdf7f954352476a799d051fbc Mon Sep 17 00:00:00 2001 From: Ian McEwen Date: Fri, 27 Dec 2024 10:04:36 -0700 Subject: [PATCH] Tweak error messaging in the onReceive function for sendtext packets --- meshtastic/__main__.py | 4 ++-- meshtastic/tests/test_main.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index 40b46907..8f2aaf92 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -74,7 +74,7 @@ def onReceive(packet, interface) -> None: args and args.sendtext and packet["to"] == interface.myInfo.my_node_num - and d["portnum"] == portnums_pb2.PortNum.TEXT_MESSAGE_APP + and d.get("portnum", portnums_pb2.PortNum.UNKNOWN_APP) == portnums_pb2.PortNum.TEXT_MESSAGE_APP ): interface.close() # after running command then exit @@ -90,7 +90,7 @@ def onReceive(packet, interface) -> None: interface.sendText(reply) except Exception as ex: - print(f"Warning: There is no field {ex} in the packet.") + print(f"Warning: Error processing received packet: {ex}.") def onConnection(interface, topic=pub.AUTO_TOPIC) -> None: # pylint: disable=W0613 diff --git a/meshtastic/tests/test_main.py b/meshtastic/tests/test_main.py index 30f3154a..0739e075 100644 --- a/meshtastic/tests/test_main.py +++ b/meshtastic/tests/test_main.py @@ -1608,7 +1608,7 @@ def test_main_onReceive_empty(caplog, capsys): assert re.search(r"in onReceive", caplog.text, re.MULTILINE) out, err = capsys.readouterr() assert re.search( - r"Warning: There is no field 'to' in the packet.", out, re.MULTILINE + r"Warning: Error processing received packet: 'to'.", out, re.MULTILINE ) assert err == ""