Highlight in logs it is a custom component when setup fails (#67559)
Co-authored-by: Joakim Sørensen <ludeeus@ludeeus.dev>
This commit is contained in:
parent
a55d20f164
commit
e7ca6b6e38
2 changed files with 30 additions and 5 deletions
|
@ -149,10 +149,17 @@ async def _async_setup_component(
|
|||
|
||||
This method is a coroutine.
|
||||
"""
|
||||
integration: loader.Integration | None = None
|
||||
|
||||
def log_error(msg: str, link: str | None = None) -> None:
|
||||
def log_error(msg: str) -> None:
|
||||
"""Log helper."""
|
||||
_LOGGER.error("Setup failed for %s: %s", domain, msg)
|
||||
if integration is None:
|
||||
custom = ""
|
||||
link = None
|
||||
else:
|
||||
custom = "" if integration.is_built_in else "custom integration "
|
||||
link = integration.documentation
|
||||
_LOGGER.error("Setup failed for %s%s: %s", custom, domain, msg)
|
||||
async_notify_setup_error(hass, domain, link)
|
||||
|
||||
try:
|
||||
|
@ -174,7 +181,7 @@ async def _async_setup_component(
|
|||
try:
|
||||
await async_process_deps_reqs(hass, config, integration)
|
||||
except HomeAssistantError as err:
|
||||
log_error(str(err), integration.documentation)
|
||||
log_error(str(err))
|
||||
return False
|
||||
|
||||
# Some integrations fail on import because they call functions incorrectly.
|
||||
|
@ -182,7 +189,7 @@ async def _async_setup_component(
|
|||
try:
|
||||
component = integration.get_component()
|
||||
except ImportError as err:
|
||||
log_error(f"Unable to import component: {err}", integration.documentation)
|
||||
log_error(f"Unable to import component: {err}")
|
||||
return False
|
||||
|
||||
processed_config = await conf_util.async_process_component_config(
|
||||
|
@ -190,7 +197,7 @@ async def _async_setup_component(
|
|||
)
|
||||
|
||||
if processed_config is None:
|
||||
log_error("Invalid config.", integration.documentation)
|
||||
log_error("Invalid config.")
|
||||
return False
|
||||
|
||||
start = timer()
|
||||
|
@ -287,6 +294,7 @@ async def async_prepare_setup_platform(
|
|||
|
||||
def log_error(msg: str) -> None:
|
||||
"""Log helper."""
|
||||
|
||||
_LOGGER.error("Unable to prepare setup for platform %s: %s", platform_path, msg)
|
||||
async_notify_setup_error(hass, platform_path)
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ import voluptuous as vol
|
|||
from homeassistant import config_entries, setup
|
||||
from homeassistant.const import EVENT_COMPONENT_LOADED, EVENT_HOMEASSISTANT_START
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import discovery
|
||||
from homeassistant.helpers.config_validation import (
|
||||
PLATFORM_SCHEMA,
|
||||
|
@ -621,6 +622,22 @@ async def test_integration_disabled(hass, caplog):
|
|||
assert disabled_reason in caplog.text
|
||||
|
||||
|
||||
async def test_integration_logs_is_custom(hass, caplog):
|
||||
"""Test we highlight it's a custom component when errors happen."""
|
||||
mock_integration(
|
||||
hass,
|
||||
MockModule("test_component1"),
|
||||
built_in=False,
|
||||
)
|
||||
with patch(
|
||||
"homeassistant.setup.async_process_deps_reqs",
|
||||
side_effect=HomeAssistantError("Boom"),
|
||||
):
|
||||
result = await setup.async_setup_component(hass, "test_component1", {})
|
||||
assert not result
|
||||
assert "Setup failed for custom integration test_component1: Boom" in caplog.text
|
||||
|
||||
|
||||
async def test_async_get_loaded_integrations(hass):
|
||||
"""Test we can enumerate loaded integations."""
|
||||
hass.config.components.add("notbase")
|
||||
|
|
Loading…
Add table
Reference in a new issue