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.
This commit is contained in:
Brett Smith 2018-06-20 15:59:56 -04:00
parent cc0082814b
commit b33c83af0a
2 changed files with 7 additions and 3 deletions

View file

@ -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)

View file

@ -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+',