wireservice / csvkit

A suite of utilities for converting to and working with CSV, the king of tabular file formats.
https://csvkit.readthedocs.io
MIT License
5.9k stars 605 forks source link

csvsql: Catch empty CSV files #1206

Closed Gill-Bates closed 8 months ago

Gill-Bates commented 10 months ago

Due to an export error I exported a 0 byte CSV. However, I did not notice this. Logically the import via csvsql failed.

The issued error message "Could not determine delimeter" is correct, but very confusing. It took me an hour to find the error.

Therefore my suggestion: couldn't csvkit check the file to be processed for existing content beforehand and then abort the process. For example with the error message "Provided CSV file is empty." ?

jpmckinney commented 8 months ago
$ echo "" | csvsql
agate/table/from_csv.py:67: RuntimeWarning: Error sniffing CSV dialect: Could not determine delimiter

This is just a warning, not an error (RuntimeWarning).

We could write to standard error and return an error code if files are empty – but in some cases it's planned for a pipeline to yield empty input (e.g. a process that updates a database with new records could something not have any new records).

So, I'll close for now, unless others frequently run into the same issue.