From b33c83af0a0f657ae0e48a7b945011d4c35dc4c6 Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Wed, 20 Jun 2018 15:59:56 -0400 Subject: [PATCH] importers: Catch and handle CSV parse errors in can_import. import2ledger bailed on one of these exceptions when trying to import a recent XLS file that had a null byte on a line. --- import2ledger/importers/_csv.py | 8 ++++++-- setup.py | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/import2ledger/importers/_csv.py b/import2ledger/importers/_csv.py index 25c4480..325dcf5 100644 --- a/import2ledger/importers/_csv.py +++ b/import2ledger/importers/_csv.py @@ -63,8 +63,12 @@ class CSVImporterBase: @classmethod def can_import(cls, input_file): - _, fields = cls._read_header(input_file) - return cls._NEEDED_KEYS.issubset(fields or ()) + try: + _, fields = cls._read_header(input_file) + except csv.Error: + return False + else: + return cls._NEEDED_KEYS.issubset(fields or ()) def __init__(self, input_file): self.entry_seed, fields = self._read_header(input_file) diff --git a/setup.py b/setup.py index 728143e..b11cee9 100755 --- a/setup.py +++ b/setup.py @@ -30,7 +30,7 @@ REQUIREMENTS['tests_require'] = [ setup( name='import2ledger', description="Import different sources of financial data to Ledger", - version='0.3', + version='0.4', author='Brett Smith', author_email='brettcsmith@brettcsmith.org', license='GNU AGPLv3+',