Skip to content

Commit

Permalink
pdplumber raise importerror
Browse files Browse the repository at this point in the history
  • Loading branch information
bosd committed Mar 30, 2023
1 parent 081a73d commit db0ac11
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/invoice2data/input/pdfplumber.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def to_text(path):
try:
import pdfplumber
except ImportError:
logger.debug("Cannot import pdfplumber")
logger.error("Cannot import pdfplumber")
raise ImportError("Cannot import pdfplumber")

raw_text = ""
raw_text = raw_text.encode(encoding='UTF-8')
Expand Down
12 changes: 10 additions & 2 deletions src/invoice2data/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ def extract_data(invoicefile, templates=None, input_module=None):
else:
input_module = pdftotext

extracted_str = input_module.to_text(invoicefile)
try:
extracted_str = input_module.to_text(invoicefile)
except Exception as e:
logger.error("Error has occured %s", e)
return False
if not isinstance(extracted_str, str) or not extracted_str.strip():
logger.error("Failed to extract text from %s using %s", invoicefile, input_module.__name__)
return False
Expand Down Expand Up @@ -235,7 +239,11 @@ def main(args=None):
templates += read_templates()
output = []
for f in args.input_files:
res = extract_data(f.name, templates=templates, input_module=input_module)
try:
res = extract_data(f.name, templates=templates, input_module=input_module)
except Exception as e:
logger.error("Error has occured %s", e)
continue
if res:
logger.info(res)
output.append(res)
Expand Down

0 comments on commit db0ac11

Please sign in to comment.