mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
better error reporting when doc parsing fails
This commit is contained in:
parent
b27d762081
commit
faed1b2d05
1 changed files with 34 additions and 31 deletions
|
@ -81,43 +81,46 @@ class DocCLI(CLI):
|
||||||
text = ''
|
text = ''
|
||||||
for module in self.args:
|
for module in self.args:
|
||||||
|
|
||||||
filename = module_loader.find_plugin(module)
|
|
||||||
if filename is None:
|
|
||||||
self.display.warning("module %s not found in %s\n" % (module, DocCLI.print_paths(module_loader)))
|
|
||||||
continue
|
|
||||||
|
|
||||||
if any(filename.endswith(x) for x in self.BLACKLIST_EXTS):
|
|
||||||
continue
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
doc, plainexamples, returndocs = module_docs.get_docstring(filename)
|
filename = module_loader.find_plugin(module)
|
||||||
except:
|
if filename is None:
|
||||||
self.display.vvv(traceback.print_exc())
|
self.display.warning("module %s not found in %s\n" % (module, DocCLI.print_paths(module_loader)))
|
||||||
self.display.error("module %s has a documentation error formatting or is missing documentation\nTo see exact traceback use -vvv" % module)
|
continue
|
||||||
continue
|
|
||||||
|
|
||||||
if doc is not None:
|
if any(filename.endswith(x) for x in self.BLACKLIST_EXTS):
|
||||||
|
continue
|
||||||
|
|
||||||
all_keys = []
|
try:
|
||||||
for (k,v) in doc['options'].iteritems():
|
doc, plainexamples, returndocs = module_docs.get_docstring(filename)
|
||||||
all_keys.append(k)
|
except:
|
||||||
all_keys = sorted(all_keys)
|
self.display.vvv(traceback.print_exc())
|
||||||
doc['option_keys'] = all_keys
|
self.display.error("module %s has a documentation error formatting or is missing documentation\nTo see exact traceback use -vvv" % module)
|
||||||
|
continue
|
||||||
|
|
||||||
doc['filename'] = filename
|
if doc is not None:
|
||||||
doc['docuri'] = doc['module'].replace('_', '-')
|
|
||||||
doc['now_date'] = datetime.date.today().strftime('%Y-%m-%d')
|
|
||||||
doc['plainexamples'] = plainexamples
|
|
||||||
doc['returndocs'] = returndocs
|
|
||||||
|
|
||||||
if self.options.show_snippet:
|
all_keys = []
|
||||||
text += DocCLI.get_snippet_text(doc)
|
for (k,v) in doc['options'].iteritems():
|
||||||
|
all_keys.append(k)
|
||||||
|
all_keys = sorted(all_keys)
|
||||||
|
doc['option_keys'] = all_keys
|
||||||
|
|
||||||
|
doc['filename'] = filename
|
||||||
|
doc['docuri'] = doc['module'].replace('_', '-')
|
||||||
|
doc['now_date'] = datetime.date.today().strftime('%Y-%m-%d')
|
||||||
|
doc['plainexamples'] = plainexamples
|
||||||
|
doc['returndocs'] = returndocs
|
||||||
|
|
||||||
|
if self.options.show_snippet:
|
||||||
|
text += DocCLI.get_snippet_text(doc)
|
||||||
|
else:
|
||||||
|
text += DocCLI.get_man_text(doc)
|
||||||
else:
|
else:
|
||||||
text += DocCLI.get_man_text(doc)
|
# this typically means we couldn't even parse the docstring, not just that the YAML is busted,
|
||||||
else:
|
# probably a quoting issue.
|
||||||
# this typically means we couldn't even parse the docstring, not just that the YAML is busted,
|
raise AnsibleError("Parsing produced an empty object.")
|
||||||
# probably a quoting issue.
|
except Exception, e:
|
||||||
self.display.warning("module %s missing documentation (or could not parse documentation)\n" % module)
|
raise AnsibleError("module %s missing documentation (or could not parse documentation): %s\n" % (module, str(e)))
|
||||||
|
|
||||||
CLI.pager(text)
|
CLI.pager(text)
|
||||||
return 0
|
return 0
|
||||||
|
|
Loading…
Reference in a new issue