mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
Ensure HomeAssistant can still restart when a library file is missing (#46664)
This commit is contained in:
parent
22dbac259b
commit
500cb17298
@ -76,6 +76,13 @@ AUTOMATION_CONFIG_PATH = "automations.yaml"
|
|||||||
SCRIPT_CONFIG_PATH = "scripts.yaml"
|
SCRIPT_CONFIG_PATH = "scripts.yaml"
|
||||||
SCENE_CONFIG_PATH = "scenes.yaml"
|
SCENE_CONFIG_PATH = "scenes.yaml"
|
||||||
|
|
||||||
|
LOAD_EXCEPTIONS = (ImportError, FileNotFoundError)
|
||||||
|
INTEGRATION_LOAD_EXCEPTIONS = (
|
||||||
|
IntegrationNotFound,
|
||||||
|
RequirementsNotFound,
|
||||||
|
*LOAD_EXCEPTIONS,
|
||||||
|
)
|
||||||
|
|
||||||
DEFAULT_CONFIG = f"""
|
DEFAULT_CONFIG = f"""
|
||||||
# Configure a default setup of Home Assistant (frontend, api, etc)
|
# Configure a default setup of Home Assistant (frontend, api, etc)
|
||||||
default_config:
|
default_config:
|
||||||
@ -689,7 +696,7 @@ async def merge_packages_config(
|
|||||||
hass, domain
|
hass, domain
|
||||||
)
|
)
|
||||||
component = integration.get_component()
|
component = integration.get_component()
|
||||||
except (IntegrationNotFound, RequirementsNotFound, ImportError) as ex:
|
except INTEGRATION_LOAD_EXCEPTIONS as ex:
|
||||||
_log_pkg_error(pack_name, comp_name, config, str(ex))
|
_log_pkg_error(pack_name, comp_name, config, str(ex))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -746,7 +753,7 @@ async def async_process_component_config(
|
|||||||
domain = integration.domain
|
domain = integration.domain
|
||||||
try:
|
try:
|
||||||
component = integration.get_component()
|
component = integration.get_component()
|
||||||
except ImportError as ex:
|
except LOAD_EXCEPTIONS as ex:
|
||||||
_LOGGER.error("Unable to import %s: %s", domain, ex)
|
_LOGGER.error("Unable to import %s: %s", domain, ex)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -825,7 +832,7 @@ async def async_process_component_config(
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
platform = p_integration.get_platform(domain)
|
platform = p_integration.get_platform(domain)
|
||||||
except ImportError:
|
except LOAD_EXCEPTIONS:
|
||||||
_LOGGER.exception("Platform error: %s", domain)
|
_LOGGER.exception("Platform error: %s", domain)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -1088,6 +1088,26 @@ async def test_component_config_exceptions(hass, caplog):
|
|||||||
in caplog.text
|
in caplog.text
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# get_component raising
|
||||||
|
caplog.clear()
|
||||||
|
assert (
|
||||||
|
await config_util.async_process_component_config(
|
||||||
|
hass,
|
||||||
|
{"test_domain": {}},
|
||||||
|
integration=Mock(
|
||||||
|
pkg_path="homeassistant.components.test_domain",
|
||||||
|
domain="test_domain",
|
||||||
|
get_component=Mock(
|
||||||
|
side_effect=FileNotFoundError(
|
||||||
|
"No such file or directory: b'liblibc.a'"
|
||||||
|
)
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
is None
|
||||||
|
)
|
||||||
|
assert "Unable to import test_domain: No such file or directory" in caplog.text
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"domain, schema, expected",
|
"domain, schema, expected",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user