From 7f616a180594e4522e6742338be18740e19a07e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 17 Feb 2018 07:39:37 +0100 Subject: [PATCH] misra.py: Add error handling when there are missing files, wrong arguments, etc --- addons/misra.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/addons/misra.py b/addons/misra.py index 4934bf8f0..085eb0b77 100644 --- a/addons/misra.py +++ b/addons/misra.py @@ -1053,10 +1053,17 @@ def loadRuleTexts(filename): continue def loadRuleTextsFromPdf(filename): + if not os.path.isfile(filename): + print('Fatal error: PDF file is not found: ' + filename) + sys.exit(1) f = tempfile.NamedTemporaryFile(delete=False) f.close() #print('tempfile:' + f.name) - subprocess.call(['pdftotext', filename, f.name]) + try: + subprocess.call(['pdftotext', filename, f.name]) + except OSError as err: + print('Fatal error: Failed to execute pdftotext: ' + str(err)) + sys.exit(1) loadRuleTexts(f.name) try: os.remove(f.name) @@ -1105,9 +1112,16 @@ for arg in sys.argv[1:]: if arg == '-verify': VERIFY = True elif arg.startswith('--rule-texts='): - loadRuleTexts(arg[13:]) + filename = arg[13:] + if not os.path.isfile(filename): + print('Fatal error: file is not found: ' + filename) + sys.exit(1) + loadRuleTexts(filename) elif arg.startswith('--misra-pdf='): loadRuleTextsFromPdf(arg[12:]) + else: + print('Fatal error: unhandled argument ' + arg) + sys.exit(1) for arg in sys.argv[1:]: if not arg.endswith('.dump'):