mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-24 04:54:00 -07:00
Improve error message for module validation (#19501)
Print out the data that fails to validate when doing
schema checking on modules
This allows easier interpretation of error messages.
From:
```
ERROR: DOCUMENTATION.notes.2: expected basestring
```
To:
```
ERROR: DOCUMENTATION.notes.2: expected basestring @ data['notes'][2].
Got {"As with C(include) this task can be static or dynamic, If static
it implies that it won't need templating nor loops nor conditionals and
will show included tasks in the --list options. Ansible will try to
autodetect what is needed, but you can set `static": 'yes|no` at task
level to control this.'}
```
This commit is contained in:
parent
48dee1b6d0
commit
dce445f956
1 changed files with 5 additions and 1 deletions
|
|
@ -39,6 +39,7 @@ from module_args import get_argument_spec
|
||||||
from schema import doc_schema, option_schema
|
from schema import doc_schema, option_schema
|
||||||
|
|
||||||
from utils import CaptureStd
|
from utils import CaptureStd
|
||||||
|
from voluptuous.humanize import humanize_error
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
import yaml.reader
|
import yaml.reader
|
||||||
|
|
@ -373,6 +374,8 @@ class ModuleValidator(Validator):
|
||||||
try:
|
try:
|
||||||
doc_schema(doc)
|
doc_schema(doc)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
for error in e.errors:
|
||||||
|
error.data = doc
|
||||||
errors.extend(e.errors)
|
errors.extend(e.errors)
|
||||||
|
|
||||||
options = doc.get('options', {})
|
options = doc.get('options', {})
|
||||||
|
|
@ -382,12 +385,13 @@ class ModuleValidator(Validator):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
for error in e.errors:
|
for error in e.errors:
|
||||||
error.path[:0] = ['options', key]
|
error.path[:0] = ['options', key]
|
||||||
|
error.data = option
|
||||||
errors.extend(e.errors)
|
errors.extend(e.errors)
|
||||||
|
|
||||||
for error in errors:
|
for error in errors:
|
||||||
path = [str(p) for p in error.path]
|
path = [str(p) for p in error.path]
|
||||||
self.errors.append('DOCUMENTATION.%s: %s' %
|
self.errors.append('DOCUMENTATION.%s: %s' %
|
||||||
('.'.join(path), error.error_message))
|
('.'.join(path), humanize_error(error.data, error)))
|
||||||
|
|
||||||
def _validate_docs(self):
|
def _validate_docs(self):
|
||||||
doc_info = self._get_docs()
|
doc_info = self._get_docs()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue