From 3f0149b7213fdcf28f94291ab5bcab2bed82ff91 Mon Sep 17 00:00:00 2001 From: Rowan Decker Date: Wed, 31 Dec 2014 01:48:08 -0600 Subject: [PATCH] Die gracefully Don't explode into a 20 line stack trace if the kll file is formatted incorrectly. Instead simply show the error message and exit with an error code (which will stop the rest of a make command). A misformatted file is most likely a user error so showing the full backtrace for debugging is not necessary. The file and line number should (hopefully) be enough to fix the parsing error. --- kll.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/kll.py b/kll.py index 57fd37a..401d22e 100755 --- a/kll.py +++ b/kll.py @@ -552,9 +552,11 @@ def processKLLFile( filename ): data = file.read() tokenSequence = tokenize( data ) #print ( pformat( tokenSequence ) ) # Display tokenization - tree = parse( tokenSequence ) - - + try: + tree = parse( tokenSequence ) + except NoParseError as e: + print("Error parsing %s. %s" % (filename, e.msg), file=sys.stderr) + sys.exit(1) ### Main Entry Point ###