From 958ce4a252c0fdd7808eb3f294f4e7fbd0b7b6b5 Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Fri, 3 Mar 2017 12:55:28 -0600 Subject: [PATCH] Create custom JSONEncoder to stringify Exceptions --- test/sanity/validate-modules/validate-modules | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/sanity/validate-modules/validate-modules b/test/sanity/validate-modules/validate-modules index edd4e96ebb2..ff8da79c2d0 100755 --- a/test/sanity/validate-modules/validate-modules +++ b/test/sanity/validate-modules/validate-modules @@ -69,6 +69,14 @@ BLACKLIST_IMPORTS = { } +class ReporterEncoder(json.JSONEncoder): + def default(self, o): + if isinstance(o, Exception): + return str(o) + + return json.JSONEncoder.default(self, o) + + class Reporter(object): @staticmethod @contextmanager @@ -135,7 +143,7 @@ class Reporter(object): ret = [len(r['errors']) for _, r in reports.items()] with Reporter._output_handle(output) as handle: - print(json.dumps(Reporter._filter_out_ok(reports), indent=4), file=handle) + print(json.dumps(Reporter._filter_out_ok(reports), indent=4, cls=ReporterEncoder), file=handle) return 3 if sum(ret) else 0 @@ -505,7 +513,6 @@ class ModuleValidator(Validator): else: self.warnings.append(msg) - def _find_ps_replacers(self): if 'WANT_JSON' not in self.text: self.errors.append((206, 'WANT_JSON not found in module'))