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
This commit is contained in:
Jason Hu 2019-02-04 10:58:06 -08:00 committed by Paulus Schoutsen
parent 79d3f533a9
commit c812176e94

View File

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