Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch ServiceNotFound message from translation cache and fix super #114084

Merged
merged 4 commits into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions homeassistant/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,17 +260,13 @@ class ServiceNotFound(HomeAssistantError):
def __init__(self, domain: str, service: str) -> None:
"""Initialize error."""
super().__init__(
self,
translation_domain="homeassistant",
translation_key="service_not_found",
translation_placeholders={"domain": domain, "service": service},
)
self.domain = domain
self.service = service

def __str__(self) -> str:
"""Return string representation."""
return f"Service {self.domain}.{self.service} not found."
self.generate_message = True


class MaxLengthExceeded(HomeAssistantError):
Expand All @@ -279,7 +275,6 @@ class MaxLengthExceeded(HomeAssistantError):
def __init__(self, value: str, property_name: str, max_length: int) -> None:
"""Initialize error."""
super().__init__(
self,
translation_domain="homeassistant",
translation_key="max_length_exceeded",
translation_placeholders={
Expand All @@ -300,7 +295,6 @@ class DependencyError(HomeAssistantError):
def __init__(self, failed_dependencies: list[str]) -> None:
"""Initialize error."""
super().__init__(
self,
f"Could not setup dependencies: {', '.join(failed_dependencies)}",
)
self.failed_dependencies = failed_dependencies
9 changes: 6 additions & 3 deletions tests/components/trace/test_websocket_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ async def test_get_trace(
enable_custom_integrations: None,
) -> None:
"""Test tracing a script or automation."""
await async_setup_component(hass, "homeassistant", {})
id = 1

def next_id():
Expand Down Expand Up @@ -206,7 +207,7 @@ def next_id():
_assert_raw_config(domain, sun_config, trace)
assert trace["blueprint_inputs"] is None
assert trace["context"]
assert trace["error"] == "Service test.automation not found."
assert trace["error"] == "Service test.automation not found"
assert trace["state"] == "stopped"
assert trace["script_execution"] == "error"
assert trace["item_id"] == "sun"
Expand Down Expand Up @@ -808,6 +809,7 @@ async def test_list_traces(
script_execution,
) -> None:
"""Test listing script and automation traces."""
await async_setup_component(hass, "homeassistant", {})
id = 1

def next_id():
Expand Down Expand Up @@ -894,7 +896,7 @@ def next_id():
assert len(_find_traces(response["result"], domain, "sun")) == 1
trace = _find_traces(response["result"], domain, "sun")[0]
assert trace["last_step"] == last_step[0].format(prefix=prefix)
assert trace["error"] == "Service test.automation not found."
assert trace["error"] == "Service test.automation not found"
assert trace["state"] == "stopped"
assert trace["script_execution"] == script_execution[0]
assert trace["timestamp"]
Expand Down Expand Up @@ -1574,6 +1576,7 @@ async def test_trace_blueprint_automation(
enable_custom_integrations: None,
) -> None:
"""Test trace of blueprint automation."""
await async_setup_component(hass, "homeassistant", {})
id = 1

def next_id():
Expand Down Expand Up @@ -1633,7 +1636,7 @@ def next_id():
assert trace["config"]["id"] == "sun"
assert trace["blueprint_inputs"] == sun_config
assert trace["context"]
assert trace["error"] == "Service test.automation not found."
assert trace["error"] == "Service test.automation not found"
assert trace["state"] == "stopped"
assert trace["script_execution"] == "error"
assert trace["item_id"] == "sun"
Expand Down
12 changes: 8 additions & 4 deletions tests/helpers/test_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -3536,6 +3536,7 @@ async def test_parallel_error(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None:
"""Test parallel action failure handling."""
await async_setup_component(hass, "homeassistant", {})
events = async_capture_events(hass, "test_event")
sequence = cv.SCRIPT_SCHEMA(
{
Expand All @@ -3552,10 +3553,10 @@ async def test_parallel_error(
assert len(events) == 0

expected_trace = {
"0": [{"error": "Service epic.failure not found."}],
"0": [{"error": "Service epic.failure not found"}],
"0/parallel/0/sequence/0": [
{
"error": "Service epic.failure not found.",
"error": "Service epic.failure not found",
"result": {
"params": {
"domain": "epic",
Expand Down Expand Up @@ -3589,6 +3590,7 @@ async def test_last_triggered(hass: HomeAssistant) -> None:

async def test_propagate_error_service_not_found(hass: HomeAssistant) -> None:
"""Test that a script aborts when a service is not found."""
await async_setup_component(hass, "homeassistant", {})
event = "test_event"
events = async_capture_events(hass, event)
sequence = cv.SCRIPT_SCHEMA([{"service": "test.script"}, {"event": event}])
Expand All @@ -3603,7 +3605,7 @@ async def test_propagate_error_service_not_found(hass: HomeAssistant) -> None:
expected_trace = {
"0": [
{
"error": "Service test.script not found.",
"error": "Service test.script not found",
"result": {
"params": {
"domain": "test",
Expand Down Expand Up @@ -5419,6 +5421,7 @@ async def test_continue_on_error_with_stop(hass: HomeAssistant) -> None:

async def test_continue_on_error_automation_issue(hass: HomeAssistant) -> None:
"""Test continue on error doesn't block action automation errors."""
await async_setup_component(hass, "homeassistant", {})
sequence = cv.SCRIPT_SCHEMA(
[
{
Expand All @@ -5436,7 +5439,7 @@ async def test_continue_on_error_automation_issue(hass: HomeAssistant) -> None:
{
"0": [
{
"error": "Service service.not_found not found.",
"error": "Service service.not_found not found",
"result": {
"params": {
"domain": "service",
Expand All @@ -5455,6 +5458,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."""
await async_setup_component(hass, "homeassistant", {})

class MyLibraryError(Exception):
"""My custom library error."""
Expand Down
3 changes: 2 additions & 1 deletion tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1670,6 +1670,7 @@ async def test_serviceregistry_remove_service(hass: HomeAssistant) -> None:

async def test_serviceregistry_service_that_not_exists(hass: HomeAssistant) -> None:
"""Test remove service that not exists."""
await async_setup_component(hass, "homeassistant", {})
calls_remove = async_capture_events(hass, EVENT_SERVICE_REMOVED)
assert not hass.services.has_service("test_xxx", "test_yyy")
hass.services.async_remove("test_xxx", "test_yyy")
Expand All @@ -1687,7 +1688,7 @@ async def test_serviceregistry_service_that_not_exists(hass: HomeAssistant) -> N
assert exc.value.domain == "test_do_not"
assert exc.value.service == "exist"

assert str(exc.value) == "Service test_do_not.exist not found."
assert str(exc.value) == "Service test_do_not.exist not found"


async def test_serviceregistry_async_service_raise_exception(
Expand Down