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:
Will Thames 2016-12-19 18:49:18 +10:00 committed by John R Barker
parent 48dee1b6d0
commit dce445f956

View file

@ -39,6 +39,7 @@ from module_args import get_argument_spec
from schema import doc_schema, option_schema
from utils import CaptureStd
from voluptuous.humanize import humanize_error
import yaml
import yaml.reader
@ -373,6 +374,8 @@ class ModuleValidator(Validator):
try:
doc_schema(doc)
except Exception as e:
for error in e.errors:
error.data = doc
errors.extend(e.errors)
options = doc.get('options', {})
@ -382,12 +385,13 @@ class ModuleValidator(Validator):
except Exception as e:
for error in e.errors:
error.path[:0] = ['options', key]
error.data = option
errors.extend(e.errors)
for error in errors:
path = [str(p) for p in error.path]
self.errors.append('DOCUMENTATION.%s: %s' %
('.'.join(path), error.error_message))
('.'.join(path), humanize_error(error.data, error)))
def _validate_docs(self):
doc_info = self._get_docs()