From 7673f572486d281804de8226c23264cbeee9c9f9 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Thu, 28 Jan 2021 09:26:41 +0100 Subject: [PATCH] Add additional error handling for automation script run (#45613) --- homeassistant/components/automation/__init__.py | 6 ++++++ homeassistant/helpers/script.py | 3 +++ tests/components/automation/test_init.py | 1 + 3 files changed, 10 insertions(+) diff --git a/homeassistant/components/automation/__init__.py b/homeassistant/components/automation/__init__.py index f1b6df48bde..201eeb5c456 100644 --- a/homeassistant/components/automation/__init__.py +++ b/homeassistant/components/automation/__init__.py @@ -404,6 +404,12 @@ class AutomationEntity(ToggleEntity, RestoreEntity): await self.action_script.async_run( variables, trigger_context, started_action ) + except (vol.Invalid, HomeAssistantError) as err: + self._logger.error( + "Error while executing automation %s: %s", + self.entity_id, + err, + ) except Exception: # pylint: disable=broad-except self._logger.exception("While executing automation %s", self.entity_id) diff --git a/homeassistant/helpers/script.py b/homeassistant/helpers/script.py index ff87312dbc2..f197664f7e6 100644 --- a/homeassistant/helpers/script.py +++ b/homeassistant/helpers/script.py @@ -291,6 +291,9 @@ class _ScriptRun: elif isinstance(exception, exceptions.ServiceNotFound): error_desc = "Service not found" + elif isinstance(exception, exceptions.HomeAssistantError): + error_desc = "Error" + else: error_desc = "Unexpected error" level = _LOG_EXCEPTION diff --git a/tests/components/automation/test_init.py b/tests/components/automation/test_init.py index 244f37ecb9c..c31af555e32 100644 --- a/tests/components/automation/test_init.py +++ b/tests/components/automation/test_init.py @@ -947,6 +947,7 @@ async def test_automation_with_error_in_script(hass, caplog): hass.bus.async_fire("test_event") await hass.async_block_till_done() assert "Service not found" in caplog.text + assert "Traceback" not in caplog.text async def test_automation_with_error_in_script_2(hass, caplog):