Raise ServiceValidationError instead of ValueError

This commit is contained in:
rikroe
2023-12-29 11:56:02 +01:00
parent 7967fb7ac1
commit 9db8b5c996
2 changed files with 6 additions and 6 deletions
@@ -26,7 +26,7 @@ from homeassistant.core import (
ServiceResponse,
SupportsResponse,
)
from homeassistant.exceptions import HomeAssistantError
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
from homeassistant.helpers.service import async_set_service_schema
from homeassistant.helpers.typing import ConfigType
from homeassistant.loader import bind_hass
@@ -246,7 +246,7 @@ def execute(hass, filename, source, data=None):
f"Expected `output` to be a dictionary, was {output_type}"
)
except ScriptError as err:
raise ValueError(f"Error executing script: {err}") from err
raise ServiceValidationError(f"Error executing script: {err}") from err
except Exception as err: # pylint: disable=broad-except
raise HomeAssistantError(
f"Error executing script ({type(err).__name__}): {err}"
+4 -4
View File
@@ -6,7 +6,7 @@ import pytest
from homeassistant.components.python_script import DOMAIN, FOLDER, execute
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
from homeassistant.helpers.service import async_get_all_descriptions
from homeassistant.setup import async_setup_component
@@ -144,7 +144,7 @@ hass.async_stop()
task = hass.async_add_executor_job(execute, hass, "test.py", source, {})
await hass.async_block_till_done()
assert type(task.exception()) == ValueError
assert type(task.exception()) == ServiceValidationError
assert "Not allowed to access async methods" in str(task.exception())
@@ -176,7 +176,7 @@ async def test_accessing_forbidden_methods(hass: HomeAssistant) -> None:
task = hass.async_add_executor_job(execute, hass, "test.py", source, {})
await hass.async_block_till_done()
assert type(task.exception()) == ValueError
assert type(task.exception()) == ServiceValidationError
assert f"Not allowed to access {name}" in str(task.exception())
@@ -540,7 +540,7 @@ output = f"hello {data.get('name', 'World')}"
"homeassistant.components.python_script.open",
mock_open(read_data=source),
create=True,
), pytest.raises(ValueError):
), pytest.raises(ServiceValidationError):
await hass.services.async_call(
"python_script",
"hello",