Retrieve sub property keys

The validation message was confusing by displaying only 1 level of
property of the service, even if the error was another level down.

Eg. if the 'files' property of 'extends' was the incorrect format,
it was displaying 'an invalid value for 'extends'', rather than
correctly retrieving 'files'.

Signed-off-by: Mazz Mosley <mazz@houseofmnowster.com>
This commit is contained in:
Mazz Mosley 2015-08-10 16:18:21 +01:00
commit e0675b50c0
2 changed files with 28 additions and 7 deletions

View file

@ -99,12 +99,14 @@ def process_errors(errors):
if error.validator_value == "array":
msg = "an"
try:
config_key = error.path[1]
type_errors.append("Service '{}' has an invalid value for '{}', it should be {} {}".format(service_name, config_key, msg, error.validator_value))
except IndexError:
config_key = error.path[0]
root_msgs.append("Service '{}' doesn\'t have any configuration options. All top level keys in your docker-compose.yml must map to a dictionary of configuration options.'".format(config_key))
# pop the service name off our path
error.path.popleft()
if len(error.path) > 0:
config_key = " ".join(["'%s'" % k for k in error.path])
type_errors.append("Service '{}' configuration key {} contains an invalid type, it should be {} {}".format(service_name, config_key, msg, error.validator_value))
else:
root_msgs.append("Service '{}' doesn\'t have any configuration options. All top level keys in your docker-compose.yml must map to a dictionary of configuration options.'".format(service_name))
elif error.validator == 'required':
config_key = error.path[1]
required.append("Service '{}' option '{}' is invalid, {}".format(service_name, config_key, _clean_error_message(error.message)))