Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: new line at end of file causes crash #29

Open
corneliusroemer opened this issue Jul 25, 2022 · 1 comment
Open

BUG: new line at end of file causes crash #29

corneliusroemer opened this issue Jul 25, 2022 · 1 comment

Comments

@corneliusroemer
Copy link

Having a \n at the end of a .csv or .tsv file shouldn't cause a crash.

Github for example asks for all files to end in an empty line, otherwise it will show a red stop sign.

In any case, if you want to enforce no empty lines at end, then the error should be caught and handled, before telling the user what the problem is.

How to reproduce

printf "a,b,c\n1,2,3\n\n" >a.csv
csv-diff a.csv a.csv --key a
Traceback (most recent call last):
  File "/usr/local/Caskroom/mambaforge/base/bin/csv-diff", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/Caskroom/mambaforge/base/lib/python3.9/site-packages/click/core.py", line 1137, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/Caskroom/mambaforge/base/lib/python3.9/site-packages/click/core.py", line 1062, in main
    rv = self.invoke(ctx)
  File "/usr/local/Caskroom/mambaforge/base/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/Caskroom/mambaforge/base/lib/python3.9/site-packages/click/core.py", line 763, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/Caskroom/mambaforge/base/lib/python3.9/site-packages/csv_diff/cli.py", line 60, in cli
    diff = compare(load(previous), load(current), show_unchanged)
  File "/usr/local/Caskroom/mambaforge/base/lib/python3.9/site-packages/csv_diff/cli.py", line 56, in load
    return load_csv(
  File "/usr/local/Caskroom/mambaforge/base/lib/python3.9/site-packages/csv_diff/__init__.py", line 26, in load_csv
    return {keyfn(r): r for r in rows}
  File "/usr/local/Caskroom/mambaforge/base/lib/python3.9/site-packages/csv_diff/__init__.py", line 26, in <dictcomp>
    return {keyfn(r): r for r in rows}
  File "/usr/local/Caskroom/mambaforge/base/lib/python3.9/site-packages/csv_diff/__init__.py", line 21, in <lambda>
    keyfn = lambda r: r[key]
KeyError: 'a'

The error should be much better, saying which line the error is on, etc.

@raveslave
Copy link

empty lines should be skipped

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants