Done
Description
While testing ASC files cut off mid-write (logger power loss), I noticed ASCReader handles a frame line that is missing its data bytes in two different ways, and neither says which line is broken.
Checked on main (59ca6a1) and on the #2154 branch (43a4d21), same result on both:
import tempfile, can
hdr = ("date Sat Nov 28 10:00:00.000 am 2026\nbase hex timestamps absolute\n"
"internal events logged\nBegin Triggerblock Sat Nov 28 10:00:00.000 am 2026\n")
for line in [" 0.100000 1 1d3 Rx d 8 01 02",
" 0.100000 CANFD 1 Rx 1d3 1 0 8 8"]:
p = tempfile.mktemp(suffix=".asc")
open(p, "w").write(hdr + line + "\nEnd TriggerBlock\n")
try:
for m in can.ASCReader(p):
print(m.dlc, bytes(m.data))
except Exception as e:
print(type(e).__name__, e)Output:
8 b'\x01\x02'
ValueError not enough values to unpack (expected 4, got 3)
- Classic CAN:
d 8with only 2 data bytes gives aMessagewithdlc=8and 2 bytes of data, with no warning. Code that trustsdlc(for example decoding with cantools) then reads past the data or fails later, far from the cause. - CAN FD: a
CANFDline that ends after the DLC/length fields raises a bareValueErrorfrom tuple unpacking in_process_fd_can_frame, without the line number or text, and the rest of the file can't be read.
I'd expect both cases to behave the same way: either skip the line with a warning that names the line, or raise one clear error type that says which line is malformed. I don't have a strong opinion on which. #2154 touches nearby parsing (TxRq and remote frames) but doesn't change these two cases.
Metadata
Metadata
Assignees
Labels
No labels
Activity