From b1ee09ff6a9215e9f2e213caaa74a5d8112ddc7f Mon Sep 17 00:00:00 2001 From: Olivier Date: Fri, 15 Mar 2024 22:15:21 +0100 Subject: [PATCH 1/2] Log exception with stack --- enocean/communicators/serialcommunicator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/enocean/communicators/serialcommunicator.py b/enocean/communicators/serialcommunicator.py index 6bc638d..4843547 100644 --- a/enocean/communicators/serialcommunicator.py +++ b/enocean/communicators/serialcommunicator.py @@ -39,7 +39,7 @@ def run(self): try: self.parse() except Exception as e: - self.logger.error('Exception occured while parsing: ' + str(e)) + self.logger.exception('Exception occured while parsing: ') time.sleep(0) self.__ser.close() From f39462dbc38a15131656b008b593fb30ae727bdb Mon Sep 17 00:00:00 2001 From: Olivier Marceau Date: Wed, 20 Mar 2024 20:56:43 +0100 Subject: [PATCH 2/2] catch IndexError coming from UTETeachInPacket --- enocean/protocol/packet.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/enocean/protocol/packet.py b/enocean/protocol/packet.py index 14fdc34..cdf5f32 100644 --- a/enocean/protocol/packet.py +++ b/enocean/protocol/packet.py @@ -149,18 +149,21 @@ def parse_msg(buf): return PARSE_RESULT.CRC_MISMATCH, buf, None # If we got this far, everything went ok (?) - if packet_type == PACKET.RADIO_ERP1: - # Need to handle UTE Teach-in here, as it's a separate packet type... - if data[0] == RORG.UTE: - packet = UTETeachInPacket(packet_type, data, opt_data) + try: + if packet_type == PACKET.RADIO_ERP1: + # Need to handle UTE Teach-in here, as it's a separate packet type... + if data[0] == RORG.UTE: + packet = UTETeachInPacket(packet_type, data, opt_data) + else: + packet = RadioPacket(packet_type, data, opt_data) + elif packet_type == PACKET.RESPONSE: + packet = ResponsePacket(packet_type, data, opt_data) + elif packet_type == PACKET.EVENT: + packet = EventPacket(packet_type, data, opt_data) else: - packet = RadioPacket(packet_type, data, opt_data) - elif packet_type == PACKET.RESPONSE: - packet = ResponsePacket(packet_type, data, opt_data) - elif packet_type == PACKET.EVENT: - packet = EventPacket(packet_type, data, opt_data) - else: - packet = Packet(packet_type, data, opt_data) + packet = Packet(packet_type, data, opt_data) + except IndexError: + return PARSE_RESULT.INCOMPLETE, buf, None return PARSE_RESULT.OK, buf, packet