mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Attach relevant config to check_config errors (#104048)
This commit is contained in:
parent
613afe322f
commit
1c817cc18c
@ -102,7 +102,10 @@ async def async_check_ha_config_file( # noqa: C901
|
||||
result.add_warning(message, domain, pack_config)
|
||||
|
||||
def _comp_error(
|
||||
ex: vol.Invalid | HomeAssistantError, domain: str, component_config: ConfigType
|
||||
ex: vol.Invalid | HomeAssistantError,
|
||||
domain: str,
|
||||
component_config: ConfigType,
|
||||
config_to_attach: ConfigType,
|
||||
) -> None:
|
||||
"""Handle errors from components."""
|
||||
if isinstance(ex, vol.Invalid):
|
||||
@ -110,9 +113,9 @@ async def async_check_ha_config_file( # noqa: C901
|
||||
else:
|
||||
message = format_homeassistant_error(ex, domain, component_config)
|
||||
if domain in frontend_dependencies:
|
||||
result.add_error(message, domain, component_config)
|
||||
result.add_error(message, domain, config_to_attach)
|
||||
else:
|
||||
result.add_warning(message, domain, component_config)
|
||||
result.add_warning(message, domain, config_to_attach)
|
||||
|
||||
async def _get_integration(
|
||||
hass: HomeAssistant, domain: str
|
||||
@ -207,7 +210,7 @@ async def async_check_ha_config_file( # noqa: C901
|
||||
)[domain]
|
||||
continue
|
||||
except (vol.Invalid, HomeAssistantError) as ex:
|
||||
_comp_error(ex, domain, config)
|
||||
_comp_error(ex, domain, config, config[domain])
|
||||
continue
|
||||
except Exception as err: # pylint: disable=broad-except
|
||||
logging.getLogger(__name__).exception(
|
||||
@ -228,7 +231,7 @@ async def async_check_ha_config_file( # noqa: C901
|
||||
if domain in config:
|
||||
result[domain] = config[domain]
|
||||
except vol.Invalid as ex:
|
||||
_comp_error(ex, domain, config)
|
||||
_comp_error(ex, domain, config, config[domain])
|
||||
continue
|
||||
|
||||
component_platform_schema = getattr(
|
||||
@ -246,7 +249,7 @@ async def async_check_ha_config_file( # noqa: C901
|
||||
try:
|
||||
p_validated = component_platform_schema(p_config)
|
||||
except vol.Invalid as ex:
|
||||
_comp_error(ex, domain, p_config)
|
||||
_comp_error(ex, domain, p_config, p_config)
|
||||
continue
|
||||
|
||||
# Not all platform components follow same pattern for platforms
|
||||
@ -282,7 +285,7 @@ async def async_check_ha_config_file( # noqa: C901
|
||||
try:
|
||||
p_validated = platform_schema(p_validated)
|
||||
except vol.Invalid as ex:
|
||||
_comp_error(ex, f"{domain}.{p_name}", p_config)
|
||||
_comp_error(ex, f"{domain}.{p_name}", p_config, p_config)
|
||||
continue
|
||||
|
||||
platforms.append(p_validated)
|
||||
|
@ -442,21 +442,19 @@ action:
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("exception", "errors", "warnings", "message", "config"),
|
||||
("exception", "errors", "warnings", "message"),
|
||||
[
|
||||
(
|
||||
Exception("Broken"),
|
||||
1,
|
||||
0,
|
||||
"Unexpected error calling config validator: Broken",
|
||||
{"value": 1},
|
||||
),
|
||||
(
|
||||
HomeAssistantError("Broken"),
|
||||
0,
|
||||
1,
|
||||
"Invalid config for [bla]: Broken",
|
||||
{"bla": {"value": 1}},
|
||||
),
|
||||
],
|
||||
)
|
||||
@ -466,7 +464,6 @@ async def test_config_platform_raise(
|
||||
errors: int,
|
||||
warnings: int,
|
||||
message: str,
|
||||
config: dict,
|
||||
) -> None:
|
||||
"""Test bad config validation platform."""
|
||||
mock_platform(
|
||||
@ -486,7 +483,7 @@ bla:
|
||||
error = CheckConfigError(
|
||||
message,
|
||||
"bla",
|
||||
config,
|
||||
{"value": 1},
|
||||
)
|
||||
_assert_warnings_errors(res, [error] * warnings, [error] * errors)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user