Skip to content

CSVReader crashes when reading an empty file #771

Closed
@ckrenslehner

Description

@ckrenslehner

The next statement in the iter function of the class CSVReader is not inside the for loop. There for a Stopiteration error is not catched.

Rewriting the code like this fixes this:

def __iter__(self):
        for (index, line) in enumerate(self.file):
            if index > 0:
                timestamp, arbitration_id, extended, remote, error, dlc, data = line.split(',')

                yield Message(
                    timestamp=float(timestamp),
                    is_remote_frame=(remote == '1'),
                    is_extended_id=(extended == '1'),
                    is_error_frame=(error == '1'),
                    arbitration_id=int(arbitration_id, base=16),
                    dlc=int(dlc),
                    data=b64decode(data),
                )

        self.stop()

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugfile-ioabout reading & writing to files

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions