mirror of
https://github.com/home-assistant/core.git
synced 2026-10-06 22:38:02 -04:00
Extend script continue_on_error suppression when calling actions (#168685)
This commit is contained in:
@@ -135,6 +135,17 @@ DEFAULT_MAX_EXCEEDED = "WARNING"
|
||||
ATTR_CUR = "current"
|
||||
ATTR_MAX = "max"
|
||||
|
||||
# Configuration errors which should cause the script to stop also when
|
||||
# continue_on_error is True.
|
||||
CONFIGURATION_ERRORS = (
|
||||
probatio.Invalid,
|
||||
exceptions.TemplateError,
|
||||
exceptions.ServiceNotFound,
|
||||
exceptions.InvalidEntityFormatError,
|
||||
exceptions.NoEntitySpecifiedError,
|
||||
exceptions.ConditionError,
|
||||
)
|
||||
|
||||
DATA_SCRIPTS: HassKey[dict[int, ScriptData]] = HassKey("helpers.script")
|
||||
DATA_SCRIPT_BREAKPOINTS: HassKey[dict[str, dict[str, set[str]]]] = HassKey(
|
||||
"helpers.script_breakpoints"
|
||||
@@ -617,19 +628,9 @@ class _ScriptRun:
|
||||
if isinstance(exception, _StopScript):
|
||||
raise exception
|
||||
|
||||
# These are incorrect scripts, and not runtime errors that need to
|
||||
# be handled and thus cannot be stopped by `continue_on_error`.
|
||||
if isinstance(
|
||||
exception,
|
||||
(
|
||||
probatio.Invalid,
|
||||
exceptions.TemplateError,
|
||||
exceptions.ServiceNotFound,
|
||||
exceptions.InvalidEntityFormatError,
|
||||
exceptions.NoEntitySpecifiedError,
|
||||
exceptions.ConditionError,
|
||||
),
|
||||
):
|
||||
# These are configuration errors which should cause the script to
|
||||
# stop also when `continue_on_error` is True.
|
||||
if isinstance(exception, CONFIGURATION_ERRORS):
|
||||
raise exception
|
||||
|
||||
# Only Home Assistant errors can be ignored.
|
||||
@@ -1080,17 +1081,24 @@ class _ScriptRun:
|
||||
params[CONF_DOMAIN] == "automation" and params[CONF_SERVICE] == "trigger"
|
||||
) or params[CONF_DOMAIN] in ("python_script", "script")
|
||||
trace_set_result(params=params, running_script=running_script)
|
||||
response_data = await self._async_run_long_action(
|
||||
self._hass.async_create_task_internal(
|
||||
self._hass.services.async_call(
|
||||
**params,
|
||||
blocking=True,
|
||||
context=self._context,
|
||||
return_response=return_response,
|
||||
),
|
||||
eager_start=True,
|
||||
try:
|
||||
response_data = await self._async_run_long_action(
|
||||
self._hass.async_create_task_internal(
|
||||
self._hass.services.async_call(
|
||||
**params,
|
||||
blocking=True,
|
||||
context=self._context,
|
||||
return_response=return_response,
|
||||
),
|
||||
eager_start=True,
|
||||
)
|
||||
)
|
||||
)
|
||||
except (*CONFIGURATION_ERRORS, exceptions.HomeAssistantError):
|
||||
raise
|
||||
except Exception as ex:
|
||||
if not self._action.get(CONF_CONTINUE_ON_ERROR, False):
|
||||
raise
|
||||
raise exceptions.HomeAssistantError(ex) from ex
|
||||
if response_variable:
|
||||
self._variables[response_variable] = response_data
|
||||
|
||||
|
||||
@@ -4176,7 +4176,7 @@ async def test_propagate_error_service_exception(hass: HomeAssistant) -> None:
|
||||
sequence = cv.SCRIPT_SCHEMA([{"action": "test.script"}, {"event": event}])
|
||||
script_obj = script.Script(hass, sequence, "Test Name", "test_domain")
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
with pytest.raises(ValueError, match="BROKEN"):
|
||||
await script_obj.async_run(context=Context())
|
||||
|
||||
assert len(events) == 0
|
||||
@@ -6600,7 +6600,7 @@ async def test_continue_on_error_automation_issue(hass: HomeAssistant) -> None:
|
||||
|
||||
|
||||
async def test_continue_on_error_unknown_error(hass: HomeAssistant) -> None:
|
||||
"""Test continue on error doesn't block unknown errors from e.g., libraries."""
|
||||
"""Test continue_on_error with unknown errors bubbling up from service calls."""
|
||||
|
||||
class MyLibraryError(Exception):
|
||||
"""My custom library error."""
|
||||
@@ -6622,8 +6622,7 @@ async def test_continue_on_error_unknown_error(hass: HomeAssistant) -> None:
|
||||
)
|
||||
script_obj = script.Script(hass, sequence, "Test Name", "test_domain")
|
||||
|
||||
with pytest.raises(MyLibraryError):
|
||||
await script_obj.async_run(context=Context())
|
||||
await script_obj.async_run(context=Context())
|
||||
|
||||
assert_action_trace(
|
||||
{
|
||||
@@ -6642,7 +6641,7 @@ async def test_continue_on_error_unknown_error(hass: HomeAssistant) -> None:
|
||||
}
|
||||
],
|
||||
},
|
||||
expected_script_execution="error",
|
||||
expected_script_execution="finished",
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user