From a8b4467763f116b7cdb35a1cc44f79451f4754ce Mon Sep 17 00:00:00 2001 From: Jason Hu Date: Mon, 4 Feb 2019 10:58:06 -0800 Subject: [PATCH] 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 --- homeassistant/config.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/homeassistant/config.py b/homeassistant/config.py index 2a9f8f64835..5dbf226ca25 100644 --- a/homeassistant/config.py +++ b/homeassistant/config.py @@ -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)