From ea6d0408091f2d5af794e0b1edfe3b715ebea459 Mon Sep 17 00:00:00 2001 From: Daniel Quinn Date: Sun, 18 Feb 2018 16:02:27 +0000 Subject: [PATCH] Monitor return codes of calls to `convert` and `unpaper` ...and handle the failures nicely. Addresses #303. --- src/documents/consumer.py | 4 ++-- src/paperless_tesseract/parsers.py | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/documents/consumer.py b/src/documents/consumer.py index 77acd1ff2..74e85b9f0 100644 --- a/src/documents/consumer.py +++ b/src/documents/consumer.py @@ -117,10 +117,10 @@ class Consumer: ) parsed_document = parser_class(doc) - thumbnail = parsed_document.get_thumbnail() - date = parsed_document.get_date() try: + thumbnail = parsed_document.get_thumbnail() + date = parsed_document.get_date() document = self._store( parsed_document.get_text(), doc, diff --git a/src/paperless_tesseract/parsers.py b/src/paperless_tesseract/parsers.py index 17e9ad05a..518489d95 100644 --- a/src/paperless_tesseract/parsers.py +++ b/src/paperless_tesseract/parsers.py @@ -233,13 +233,15 @@ def run_convert(*args): if settings.CONVERT_TMPDIR: environment["MAGICK_TMPDIR"] = settings.CONVERT_TMPDIR - subprocess.Popen(args, env=environment).wait() + if not subprocess.Popen(args, env=environment).wait() == 0: + raise ParseError("Convert failed at {}".format(args)) def run_unpaper(args): unpaper, pnm = args - subprocess.Popen( - (unpaper, pnm, pnm.replace(".pnm", ".unpaper.pnm"))).wait() + command_args = unpaper, pnm, pnm.replace(".pnm", ".unpaper.pnm") + if not subprocess.Popen(command_args).wait() == 0: + raise ParseError("Unpaper failed at {}".format(command_args)) def strip_excess_whitespace(text):