quentinsf / icsv2ledger

Interactive importing of CSV files to Ledger
196 stars 70 forks source link

Blank lines at end of csv file cause IndexError #54

Closed kjowens closed 11 years ago

kjowens commented 11 years ago

If you have extra lines at the end of a csv file it causes this error

$ ./icsv2ledger.py -a amex amextest.csv amextest.txt
Traceback (most recent call last):
  File "./icsv2ledger.py", line 631, in <module>
    main()
  File "./icsv2ledger.py", line 628, in main
    process_input_output(options.infile, options.outfile)
  File "./icsv2ledger.py", line 610, in process_input_output
    ledger_lines = process_csv_lines(csv_lines)
  File "./icsv2ledger.py", line 621, in process_csv_lines
    options)
  File "./icsv2ledger.py", line 314, in __init__
    self.date = fields[options.date - 1]
IndexError: list index out of range

It seems like a common enough mistake that there should be some way to handle it, either to ignore blank lines and throw a warning, or stop if there are blank lines at the end of a csv file and show a message that they need to be removed.

petdr commented 11 years ago

Commit https://github.com/quentinsf/icsv2ledger/commit/4fe56c8bd7025a5d1989ba453082e325bf391511 now ignores any blank lines in the csv.