From 9150ba0dce83a4273e25001d1461d02d8c114ea2 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Tue, 6 Mar 2018 11:09:33 +0000 Subject: [PATCH] Improve error output from failing to parse examples --- scripts/templating/matrix_templates/units.py | 28 +++++++++++++------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/scripts/templating/matrix_templates/units.py b/scripts/templating/matrix_templates/units.py index 1540a7fd..d8cfe1e3 100644 --- a/scripts/templating/matrix_templates/units.py +++ b/scripts/templating/matrix_templates/units.py @@ -694,15 +694,25 @@ class MatrixUnits(Units): for filename in os.listdir(path): if not filename.startswith("m."): continue - with open(os.path.join(path, filename), "r") as f: - event_name = filename.split("#")[0] - example = json.loads(f.read()) - - examples[filename] = examples.get(filename, []) - examples[filename].append(example) - if filename != event_name: - examples[event_name] = examples.get(event_name, []) - examples[event_name].append(example) + + event_name = filename.split("#")[0] + filepath = os.path.join(path, filename) + logger.info("Reading event example: %s" % filepath) + try: + with open(filepath, "r") as f: + example = json.load(f) + examples[filename] = examples.get(filename, []) + examples[filename].append(example) + if filename != event_name: + examples[event_name] = examples.get(event_name, []) + examples[event_name].append(example) + except Exception, e: + e2 = Exception("Error reading event example "+filepath+": "+ + str(e)) + # throw the new exception with the old stack trace, so that + # we don't lose information about where the error occurred. + raise e2, None, sys.exc_info()[2] + return examples def load_event_schemas(self):