add custom warning when run_command fails

This commit is contained in:
svlandeg 2020-06-30 17:28:43 +02:00
parent 39953c7c60
commit 60f97bc519
2 changed files with 7 additions and 1 deletions

View File

@ -539,6 +539,7 @@ class Errors(object):
E199 = ("Unable to merge 0-length span at doc[{start}:{end}].")
# TODO: fix numbering after merging develop into master
E970 = ("Can not execute command '{str_command}'. Do you have '{tool}' installed?")
E971 = ("Found incompatible lengths in Doc.from_array: {array_length} for the "
"array and {doc_length} for the Doc itself.")
E972 = ("Example.__init__ got None for '{arg}'. Requires Doc.")

View File

@ -452,7 +452,12 @@ def run_command(command: Union[str, List[str]]) -> None:
"""
if isinstance(command, str):
command = split_command(command)
status = subprocess.call(command, env=os.environ.copy())
try:
status = subprocess.call(command, env=os.environ.copy())
except FileNotFoundError:
raise FileNotFoundError(
Errors.E970.format(str_command=" ".join(command), tool=command[0])
)
if status != 0:
sys.exit(status)