Improve error message for invalid key in config (#1975)

* Improve error message for invalid key in config

* Refactor log exception in config validation
This commit is contained in:
Daniel Høyer Iversen 2016-05-07 16:35:42 +02:00 committed by Paulus Schoutsen
parent 67f3fcc5cf
commit 21dd8162b3
2 changed files with 18 additions and 7 deletions

View file

@ -146,6 +146,18 @@ def time_period_str(value):
time_period = vol.Any(time_period_str, timedelta, time_period_dict)
def log_exception(logger, ex, domain):
"""Generate log exception for config validation."""
message = 'Invalid config for [{}]: '.format(domain)
if 'extra keys not allowed' in ex.error_message:
message += '[{}] is an invalid option for [{}]. Check: {}->{}.'\
.format(ex.path[-1], domain, domain,
'->'.join('%s' % m for m in ex.path))
else:
message += ex.error_message
logger.error(message)
def match_all(value):
"""Validator that matches all values."""
return value