From df9e286e9cddbbbf2ec2a86fc0863c4458562058 Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Sat, 1 Jun 2019 01:35:15 -0700 Subject: [PATCH] Make bypassed exception clearer --- src/ocrmypdf/_sync.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/ocrmypdf/_sync.py b/src/ocrmypdf/_sync.py index de408919..62fc5a39 100644 --- a/src/ocrmypdf/_sync.py +++ b/src/ocrmypdf/_sync.py @@ -259,6 +259,12 @@ def exec_concurrent(context): copy_final(pdf, context.options.output_file, context) +class NeverRaise(Exception): + """An exception that is never raised""" + + pass + + def run_pipeline(options, api=False): log = make_logger(options, __name__) @@ -293,22 +299,16 @@ def run_pipeline(options, api=False): # Execute the pipeline exec_concurrent(context) - except KeyboardInterrupt as e: - if api: - raise + except (KeyboardInterrupt if not api else NeverRaise) as e: log.error("KeyboardInterrupt") return ExitCode.ctrl_c - except ExitCodeException as e: - if api: - raise + except (ExitCodeException if not api else NeverRaise) as e: if str(e): log.error("%s: %s", type(e).__name__, str(e)) else: log.error(type(e).__name__) return e.exit_code - except Exception as e: - if api: - raise + except (Exception if not api else NeverRaise) as e: log.exception("An exception occurred while executing the pipeline") return ExitCode.other_error finally: