api: short-circuit exception handler, as caller should provide their own

This commit is contained in:
James R. Barlow
2019-05-22 18:30:30 -07:00
parent db69b4d11a
commit a139e64c67
2 changed files with 12 additions and 3 deletions
+11 -2
View File
@@ -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
+1 -1
View File
@@ -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)