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.
When
rows_from_file()is called with an empty file (or a file containing only whitespace) and no explicitformatargument, it raises an uncaughtcsv.Error: Could not determine delimiter.Repro:
Root cause: In
utils.py, the auto-detect branch strips the first 2048 bytes and passes the result tocsv.Sniffer().sniff(). Whenfirst_bytes.strip()is empty (empty file or whitespace only),sniff("")raisescsv.Errorrather than returning gracefully.The fix is to return an empty iterator before reaching
sniff()whenfirst_bytesis empty.