mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 18:27:09 +00:00
Better general/fallback error message and traceback for unknown config errors (#44655)
* Include error repr in config error message is str(error) yields nothing * Log traceback for config errors we don't have a "friendly" formatter for
This commit is contained in:
parent
853420d972
commit
67eebce55a
@ -412,17 +412,19 @@ def async_log_exception(
|
|||||||
"""
|
"""
|
||||||
if hass is not None:
|
if hass is not None:
|
||||||
async_notify_setup_error(hass, domain, link)
|
async_notify_setup_error(hass, domain, link)
|
||||||
_LOGGER.error(_format_config_error(ex, domain, config, link))
|
message, is_friendly = _format_config_error(ex, domain, config, link)
|
||||||
|
_LOGGER.error(message, exc_info=not is_friendly and ex)
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _format_config_error(
|
def _format_config_error(
|
||||||
ex: Exception, domain: str, config: Dict, link: Optional[str] = None
|
ex: Exception, domain: str, config: Dict, link: Optional[str] = None
|
||||||
) -> str:
|
) -> Tuple[str, bool]:
|
||||||
"""Generate log exception for configuration validation.
|
"""Generate log exception for configuration validation.
|
||||||
|
|
||||||
This method must be run in the event loop.
|
This method must be run in the event loop.
|
||||||
"""
|
"""
|
||||||
|
is_friendly = False
|
||||||
message = f"Invalid config for [{domain}]: "
|
message = f"Invalid config for [{domain}]: "
|
||||||
if isinstance(ex, vol.Invalid):
|
if isinstance(ex, vol.Invalid):
|
||||||
if "extra keys not allowed" in ex.error_message:
|
if "extra keys not allowed" in ex.error_message:
|
||||||
@ -433,8 +435,9 @@ def _format_config_error(
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
message += f"{humanize_error(config, ex)}."
|
message += f"{humanize_error(config, ex)}."
|
||||||
|
is_friendly = True
|
||||||
else:
|
else:
|
||||||
message += str(ex)
|
message += str(ex) or repr(ex)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
domain_config = config.get(domain, config)
|
domain_config = config.get(domain, config)
|
||||||
@ -449,7 +452,7 @@ def _format_config_error(
|
|||||||
if domain != CONF_CORE and link:
|
if domain != CONF_CORE and link:
|
||||||
message += f"Please check the docs at {link}"
|
message += f"Please check the docs at {link}"
|
||||||
|
|
||||||
return message
|
return message, is_friendly
|
||||||
|
|
||||||
|
|
||||||
async def async_process_ha_core_config(hass: HomeAssistant, config: Dict) -> None:
|
async def async_process_ha_core_config(hass: HomeAssistant, config: Dict) -> None:
|
||||||
|
@ -78,7 +78,7 @@ async def async_check_ha_config_file(hass: HomeAssistant) -> HomeAssistantConfig
|
|||||||
|
|
||||||
def _comp_error(ex: Exception, domain: str, config: ConfigType) -> None:
|
def _comp_error(ex: Exception, domain: str, config: ConfigType) -> None:
|
||||||
"""Handle errors from components: async_log_exception."""
|
"""Handle errors from components: async_log_exception."""
|
||||||
result.add_error(_format_config_error(ex, domain, config), domain, config)
|
result.add_error(_format_config_error(ex, domain, config)[0], domain, config)
|
||||||
|
|
||||||
# Load configuration.yaml
|
# Load configuration.yaml
|
||||||
config_path = hass.config.path(YAML_CONFIG_FILE)
|
config_path = hass.config.path(YAML_CONFIG_FILE)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user