mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 04:50:05 +00:00
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:
committed by
Paulus Schoutsen
parent
67f3fcc5cf
commit
21dd8162b3
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user