Fix the line reference in config error message (#20743)

* Fix the line reference in config error message

* Fix platform config validation

* Fix test

* Handle error in error handling routine
pull/20794/head
Jason Hu 2019-02-04 10:58:06 -08:00 committed by Paulus Schoutsen
parent cfa03a408e
commit a8b4467763
1 changed files with 8 additions and 4 deletions

View File

@ -446,7 +446,11 @@ def _format_config_error(ex: vol.Invalid, domain: str, config: Dict) -> str:
else:
message += '{}.'.format(humanize_error(config, ex))
domain_config = config.get(domain, config)
try:
domain_config = config.get(domain, config)
except AttributeError:
domain_config = config
message += " (See {}, line {}). ".format(
getattr(domain_config, '__config_file__', '?'),
getattr(domain_config, '__line__', '?'))
@ -759,7 +763,7 @@ def async_process_component_config(
p_validated = component.PLATFORM_SCHEMA( # type: ignore
p_config)
except vol.Invalid as ex:
async_log_exception(ex, domain, config, hass)
async_log_exception(ex, domain, p_config, hass)
continue
# Not all platform components follow same pattern for platforms
@ -779,10 +783,10 @@ def async_process_component_config(
# pylint: disable=no-member
try:
p_validated = platform.PLATFORM_SCHEMA( # type: ignore
p_validated)
p_config)
except vol.Invalid as ex:
async_log_exception(ex, '{}.{}'.format(domain, p_name),
p_validated, hass)
p_config, hass)
continue
platforms.append(p_validated)