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:
parent
67f3fcc5cf
commit
21dd8162b3
2 changed files with 18 additions and 7 deletions
|
@ -14,6 +14,7 @@ import homeassistant.components as core_components
|
|||
import homeassistant.components.group as group
|
||||
import homeassistant.config as config_util
|
||||
import homeassistant.core as core
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
import homeassistant.loader as loader
|
||||
import homeassistant.util.dt as date_util
|
||||
import homeassistant.util.location as loc_util
|
||||
|
@ -103,7 +104,7 @@ def _setup_component(hass, domain, config):
|
|||
try:
|
||||
config = component.CONFIG_SCHEMA(config)
|
||||
except vol.MultipleInvalid as ex:
|
||||
_LOGGER.error('Invalid config for [%s]: %s', domain, ex)
|
||||
cv.log_exception(_LOGGER, ex, domain)
|
||||
return False
|
||||
|
||||
elif hasattr(component, 'PLATFORM_SCHEMA'):
|
||||
|
@ -113,8 +114,7 @@ def _setup_component(hass, domain, config):
|
|||
try:
|
||||
p_validated = component.PLATFORM_SCHEMA(p_config)
|
||||
except vol.MultipleInvalid as ex:
|
||||
_LOGGER.error('Invalid platform config for [%s]: %s. %s',
|
||||
domain, ex, p_config)
|
||||
cv.log_exception(_LOGGER, ex, domain)
|
||||
return False
|
||||
|
||||
# Not all platform components follow same pattern for platforms
|
||||
|
@ -135,9 +135,8 @@ def _setup_component(hass, domain, config):
|
|||
try:
|
||||
p_validated = platform.PLATFORM_SCHEMA(p_validated)
|
||||
except vol.MultipleInvalid as ex:
|
||||
_LOGGER.error(
|
||||
'Invalid platform config for [%s.%s]: %s. %s',
|
||||
domain, p_name, ex, p_config)
|
||||
cv.log_exception(_LOGGER, ex, '{}.{}'
|
||||
.format(domain, p_name))
|
||||
return False
|
||||
|
||||
platforms.append(p_validated)
|
||||
|
@ -233,7 +232,7 @@ def from_config_dict(config, hass=None, config_dir=None, enable_log=True,
|
|||
process_ha_core_config(hass, config_util.CORE_CONFIG_SCHEMA(
|
||||
config.get(core.DOMAIN, {})))
|
||||
except vol.MultipleInvalid as ex:
|
||||
_LOGGER.error('Invalid config for [homeassistant]: %s', ex)
|
||||
cv.log_exception(_LOGGER, ex, 'homeassistant')
|
||||
return None
|
||||
|
||||
process_ha_config_upgrade(hass)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue