Ensure HomeAssistant can still restart when a library file is missing (#46664)

This commit is contained in:
J. Nick Koston 2021-02-19 20:22:48 -10:00 committed by GitHub
parent 22dbac259b
commit 500cb17298
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 3 deletions

View file

@ -76,6 +76,13 @@ AUTOMATION_CONFIG_PATH = "automations.yaml"
SCRIPT_CONFIG_PATH = "scripts.yaml"
SCENE_CONFIG_PATH = "scenes.yaml"
LOAD_EXCEPTIONS = (ImportError, FileNotFoundError)
INTEGRATION_LOAD_EXCEPTIONS = (
IntegrationNotFound,
RequirementsNotFound,
*LOAD_EXCEPTIONS,
)
DEFAULT_CONFIG = f"""
# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:
@ -689,7 +696,7 @@ async def merge_packages_config(
hass, domain
)
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))
continue
@ -746,7 +753,7 @@ async def async_process_component_config(
domain = integration.domain
try:
component = integration.get_component()
except ImportError as ex:
except LOAD_EXCEPTIONS as ex:
_LOGGER.error("Unable to import %s: %s", domain, ex)
return None
@ -825,7 +832,7 @@ async def async_process_component_config(
try:
platform = p_integration.get_platform(domain)
except ImportError:
except LOAD_EXCEPTIONS:
_LOGGER.exception("Platform error: %s", domain)
continue

View file

@ -1088,6 +1088,26 @@ async def test_component_config_exceptions(hass, caplog):
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(
"domain, schema, expected",