From 2889067ecec7b361c10880148ae2f82021d4f204 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Sun, 15 Mar 2020 11:51:02 -0700 Subject: [PATCH] Make sure panel_custom won't crash on invalid data (#32835) * Make sure panel_custom won't crash on invalid data * Add a test --- homeassistant/components/hassio/manifest.json | 3 ++- homeassistant/components/panel_custom/__init__.py | 15 +++++++++------ tests/components/panel_custom/test_init.py | 14 ++++++++++++++ 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/hassio/manifest.json b/homeassistant/components/hassio/manifest.json index d3dd7dc9c94..cd004db4c93 100644 --- a/homeassistant/components/hassio/manifest.json +++ b/homeassistant/components/hassio/manifest.json @@ -3,6 +3,7 @@ "name": "Hass.io", "documentation": "https://www.home-assistant.io/hassio", "requirements": [], - "dependencies": ["http", "panel_custom"], + "dependencies": ["http"], + "after_dependencies": ["panel_custom"], "codeowners": ["@home-assistant/hass-io"] } diff --git a/homeassistant/components/panel_custom/__init__.py b/homeassistant/components/panel_custom/__init__.py index cf861992bd6..82572d7396c 100644 --- a/homeassistant/components/panel_custom/__init__.py +++ b/homeassistant/components/panel_custom/__init__.py @@ -146,8 +146,6 @@ async def async_setup(hass, config): if DOMAIN not in config: return True - success = False - for panel in config[DOMAIN]: name = panel[CONF_COMPONENT_NAME] @@ -182,8 +180,13 @@ async def async_setup(hass, config): hass.http.register_static_path(url, panel_path) kwargs["html_url"] = url - await async_register_panel(hass, **kwargs) + try: + await async_register_panel(hass, **kwargs) + except ValueError as err: + _LOGGER.error( + "Unable to register panel %s: %s", + panel.get(CONF_SIDEBAR_TITLE, name), + err, + ) - success = True - - return success + return True diff --git a/tests/components/panel_custom/test_init.py b/tests/components/panel_custom/test_init.py index e6bc56d080e..5f7161089f6 100644 --- a/tests/components/panel_custom/test_init.py +++ b/tests/components/panel_custom/test_init.py @@ -181,3 +181,17 @@ async def test_url_option_conflict(hass): for config in to_try: result = await setup.async_setup_component(hass, "panel_custom", config) assert not result + + +async def test_url_path_conflict(hass): + """Test config with overlapping url path.""" + assert await setup.async_setup_component( + hass, + "panel_custom", + { + "panel_custom": [ + {"name": "todo-mvc", "js_url": "/local/bla.js"}, + {"name": "todo-mvc", "js_url": "/local/bla.js"}, + ] + }, + )