From 9989ffea37eabf8cd6ab5de820df9b05900d78fb Mon Sep 17 00:00:00 2001 From: Guthrie McAfee Armstrong Date: Wed, 21 Sep 2022 13:07:54 -0400 Subject: [PATCH] catch ValueError, simplify try/except on top-level job runs See https://github.com/freedomofpress/dangerzone/pull/167#discussion_r915757189 --- container/dangerzone.py | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/container/dangerzone.py b/container/dangerzone.py index 11aef6f..13f39cc 100644 --- a/container/dangerzone.py +++ b/container/dangerzone.py @@ -369,25 +369,16 @@ def main() -> int: converter = DangerzoneConverter() - if sys.argv[1] == "document-to-pixels": - try: - job.document_to_pixels() - except (RuntimeError, TimeoutError) as e: - job.update_progress(str(e), error=True) - return 1 - else: - return 0 # Success! - - elif sys.argv[1] == "pixels-to-pdf": - try: - job.pixels_to_pdf() - except (RuntimeError, TimeoutError) as e: - job.update_progress(str(e), error=True) - return 1 - else: - return 0 # Success! - - return -1 + try: + if sys.argv[1] == "document-to-pixels": + converter.document_to_pixels() + elif sys.argv[1] == "pixels-to-pdf": + converter.pixels_to_pdf() + except (RuntimeError, TimeoutError, ValueError) as e: + converter.update_progress(str(e), error=True) + return 1 + else: + return 0 # Success! if __name__ == "__main__":