Skip to content

rows_from_file() crashes with csv.Error on empty or whitespace-only files #808

Description

@ikatyal2110

When rows_from_file() is called with an empty file (or a file containing only whitespace) and no explicit format argument, it raises an uncaught csv.Error: Could not determine delimiter.

Repro:

import io
from sqlite_utils.utils import rows_from_file

rows, fmt = rows_from_file(io.BytesIO(b""))
list(rows)  # raises csv.Error: Could not determine delimiter

Root cause: In utils.py, the auto-detect branch strips the first 2048 bytes and passes the result to csv.Sniffer().sniff(). When first_bytes.strip() is empty (empty file or whitespace only), sniff("") raises csv.Error rather than returning gracefully.

The fix is to return an empty iterator before reaching sniff() when first_bytes is empty.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions