Skip to content

Commit ffea69b

Browse files
authored
Merge pull request #903 from mattculler/feature/no-none-format-str
Format exception when msg_id is None
2 parents 4411d9e + f636041 commit ffea69b

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

src/canmatrix/Frame.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -624,8 +624,12 @@ def unpack(self, data: bytes,
624624
rx_length = len(data)
625625
if rx_length != self.size:
626626
msg_id = self.arbitration_id.id if self.arbitration_id.id != 0 else self.header_id
627-
628-
logging.warning(f"Received message 0x{msg_id:08X} with length {rx_length}, expected {self.size}")
627+
if msg_id is None:
628+
msg_description = "nothing"
629+
else:
630+
msg_description = f"message 0x{msg_id:08X} with length {rx_length}"
631+
msg = f"Received {msg_description}, expected {self.size}"
632+
logging.warning(msg)
629633

630634
if allow_truncated:
631635
# pad the data with 0xff to prevent the codec from
@@ -638,8 +642,7 @@ def unpack(self, data: bytes,
638642

639643
if len(data) != self.size:
640644
# return None
641-
raise DecodingFrameLength(
642-
f"Received message 0x{msg_id:04X} with wrong data size: {rx_length} instead of {self.size}")
645+
raise DecodingFrameLength(f"{msg} (wrong data size)")
643646

644647
if self.is_pdu_container:
645648
# note: PDU-Container without header is possible for ARXML-Container-PDUs with NO-HEADER

0 commit comments

Comments
 (0)