diff --git a/src/ocrmypdf/_sync.py b/src/ocrmypdf/_sync.py index 5c509d22..a1a3f083 100644 --- a/src/ocrmypdf/_sync.py +++ b/src/ocrmypdf/_sync.py @@ -239,7 +239,7 @@ def exec_concurrent(context): copy_final(pdf, context.options.output_file, context) -def run_pipeline(options): +def run_pipeline(options, api=False): log = make_logger(options, __name__) # Any changes to options will not take effect for options that are already @@ -277,12 +277,21 @@ def run_pipeline(options): # Execute the pipeline exec_concurrent(context) except KeyboardInterrupt as e: + if api: + raise log.error("KeyboardInterrupt") return ExitCode.ctrl_c except ExitCodeException as e: - log.error("%s: %s" % (type(e).__name__, str(e))) + if api: + raise + 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 log.exception("An exception occurred while executing the pipeline") return ExitCode.other_error diff --git a/src/ocrmypdf/api.py b/src/ocrmypdf/api.py index fc22b20b..2d6ccecf 100644 --- a/src/ocrmypdf/api.py +++ b/src/ocrmypdf/api.py @@ -179,4 +179,4 @@ def ocrmypdf( # pylint: disable=unused-argument ): options = create_options(**locals()) check_options(options) - return run_pipeline(options) + return run_pipeline(options, api=True)