From e6631db6b6337bc65d98e744c3bf3312a48f1c42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yago=20Gonz=C3=A1lez?= Date: Thu, 12 Jul 2018 17:26:29 +0530 Subject: [PATCH] api docs: Raise exception on missing argument file. If the argument table generator isn't able to reach a file that is supposed to read, the two most likely causes are: - The source .md documentation file that is requesting the table has a typo in the path. - The file with the arguments isn't there, for some reason. In either case, we don't want the server to fail silently-ish and display the docs as if there was no arguments for that endpoint. That's why the most logic thing to do is to raise an exception and let the admins know that there's something wrong. --- .../bugdown/api_arguments_table_generator.py | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/zerver/lib/bugdown/api_arguments_table_generator.py b/zerver/lib/bugdown/api_arguments_table_generator.py index 340f923b72..9aa10eaa9d 100644 --- a/zerver/lib/bugdown/api_arguments_table_generator.py +++ b/zerver/lib/bugdown/api_arguments_table_generator.py @@ -50,23 +50,15 @@ class APIArgumentsTablePreprocessor(Preprocessor): parent_dir = self.base_path filename = os.path.normpath(os.path.join(parent_dir, filename)) - try: - if is_openapi_format: - endpoint, method = doc_name.rsplit(':', 1) - arguments = get_openapi_parameters(endpoint, method) - else: - with open(filename, 'r') as fp: - json_obj = ujson.load(fp) - arguments = json_obj[doc_name] + if is_openapi_format: + endpoint, method = doc_name.rsplit(':', 1) + arguments = get_openapi_parameters(endpoint, method) + else: + with open(filename, 'r') as fp: + json_obj = ujson.load(fp) + arguments = json_obj[doc_name] - text = self.render_table(arguments) - except Exception as e: - print('Warning: could not find file {}. Ignoring ' - 'statement. Error: {}'.format(filename, e)) - # If the file cannot be opened, just substitute an empty line - # in place of the macro include line - lines[loc] = REGEXP.sub('', line) - break + text = self.render_table(arguments) # The line that contains the directive to include the macro # may be preceded or followed by text or tags, in that case