mirror of https://github.com/zulip/zulip.git
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.
This commit is contained in:
parent
f75c0e29f4
commit
e6631db6b6
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue