From 500cb172981b743ea8463183758337427efb94ce Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 19 Feb 2021 20:22:48 -1000 Subject: [PATCH] Ensure HomeAssistant can still restart when a library file is missing (#46664) --- homeassistant/config.py | 13 ++++++++++--- tests/test_config.py | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/homeassistant/config.py b/homeassistant/config.py index 73d0273d1c0..90df365c349 100644 --- a/homeassistant/config.py +++ b/homeassistant/config.py @@ -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 diff --git a/tests/test_config.py b/tests/test_config.py index 7dd7d61e8ef..299cf9caa73 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -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",