Skip to content

ASCReader: truncated frame lines either load silently with missing data or fail with a bare ValueError #2160

Done

Description

@DanShinde

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)
  1. Classic CAN: d 8 with only 2 data bytes gives a Message with dlc=8 and 2 bytes of data, with no warning. Code that trusts dlc (for example decoding with cantools) then reads past the data or fails later, far from the cause.
  2. CAN FD: a CANFD line that ends after the DLC/length fields raises a bare ValueError from 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions