From cbf49a307e71cb087d26f934e004999f892fc753 Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Fri, 1 Apr 2016 07:33:59 -0400 Subject: [PATCH] Enhanced error handling for rest_parameters parser Instead of throwing a KeyError if the lookup file isn't what we expected, and dying, throw a warning and skip the key in content. This makes it a bit easier to understand what's wrong and how to address it for people not familiar with the code. Change-Id: I0d1cb60b5a1010d00e5290f697bbde601fd5f221 --- api-ref/ext/rest_parameters.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/api-ref/ext/rest_parameters.py b/api-ref/ext/rest_parameters.py index 048e93f97f..4f2aa22fcf 100644 --- a/api-ref/ext/rest_parameters.py +++ b/api-ref/ext/rest_parameters.py @@ -122,14 +122,20 @@ class RestParametersDirective(Table): new_content = list() for paramlist in parsed: for name, ref in paramlist.items(): - new_content.append((name, lookup[ref])) + if ref in lookup: + new_content.append((name, lookup[ref])) + else: + self.env.warn( + self.env.docname, + "No field definition for %s found in %s. Skipping." % + (ref, fpath)) # self.app.info("New content %s" % new_content) self.yaml = new_content def run(self): - env = self.state.document.settings.env - self.app = env.app + self.env = self.state.document.settings.env + self.app = self.env.app # Make sure we have some content, which should be yaml that # defines some parameters. @@ -149,7 +155,7 @@ class RestParametersDirective(Table): # NOTE(sdague): it's important that we pop the arg otherwise # we end up putting the filename as the table caption. - rel_fpath, fpath = env.relfn2path(self.arguments.pop()) + rel_fpath, fpath = self.env.relfn2path(self.arguments.pop()) self.yaml_from_file(fpath) self.max_cols = len(self.headers)