Better error messages for input file not found or invalid

Not as good finding a general way to deal with ruffus exceptions, but
better than nil.
This commit is contained in:
James R. Barlow
2015-12-04 03:07:53 -08:00
parent acb31abe86
commit 276fe49867
2 changed files with 33 additions and 1 deletions
+16 -1
View File
@@ -880,10 +880,16 @@ def available_cpu_count():
return 1
def cleanup_ruffus_error_message(msg):
msg = re.sub(r'\s+', r' ', msg, re.MULTILINE)
msg = re.sub(r"\((.+?)\)", r'\1', msg, re.MULTILINE)
msg = msg.strip()
return msg
def run_pipeline():
if not options.jobs or options.jobs == 1:
options.jobs = available_cpu_count()
try:
cmdline.run(options)
except ruffus_exceptions.RethrownJobError as e:
@@ -898,6 +904,15 @@ def run_pipeline():
return eval(
exc_value,
{'ExitCode': ExitCode}, {'exc_value': exc_value})
elif exc_name == 'ruffus.ruffus_exceptions.MissingInputFileError':
print(cleanup_ruffus_error_message(exc_value))
return ExitCode.input_file
elif exc_name == 'builtins.TypeError':
if task_name == 'split_pages':
print("Input file '{0}' is not a valid PDF".format(
options.input_file))
return ExitCode.input_file
return ExitCode.other_error
if not validate_pdfa(options.output_file, _log):
+17
View File
@@ -337,3 +337,20 @@ def test_uppercase_extension():
os.unlink(_make_input("UPPERCASE.PDF"))
def test_input_file_not_found():
input_file = "does not exist.pdf"
sh, out, err = run_ocrmypdf_sh(
_make_input(input_file),
_make_output("will not happen.pdf"))
assert sh.returncode == ExitCode.input_file
assert (input_file in out or input_file in err)
def test_input_file_not_a_pdf():
input_file = __file__ # Try to OCR this file
sh, out, err = run_ocrmypdf_sh(
_make_input(input_file),
_make_output("will not happen.pdf"))
assert sh.returncode == ExitCode.input_file
assert (input_file in out or input_file in err)