mirror of
https://github.com/home-assistant/core.git
synced 2026-04-20 16:39:02 +02:00
Add exception translations for Splunk setup errors (#163579)
This commit is contained in:
@@ -179,24 +179,42 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
)
|
||||
except ClientConnectionError as err:
|
||||
raise ConfigEntryNotReady(
|
||||
f"Connection error connecting to Splunk at {host}:{port}: {err}"
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="connection_error",
|
||||
translation_placeholders={
|
||||
"host": host,
|
||||
"port": str(port),
|
||||
"error": str(err),
|
||||
},
|
||||
) from err
|
||||
except TimeoutError as err:
|
||||
raise ConfigEntryNotReady(
|
||||
f"Timeout connecting to Splunk at {host}:{port}"
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="timeout_connect",
|
||||
translation_placeholders={"host": host, "port": str(port)},
|
||||
) from err
|
||||
except Exception as err:
|
||||
_LOGGER.exception("Unexpected error setting up Splunk")
|
||||
raise ConfigEntryNotReady(
|
||||
f"Unexpected error connecting to Splunk: {err}"
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="unexpected_error",
|
||||
translation_placeholders={
|
||||
"host": host,
|
||||
"port": str(port),
|
||||
"error": str(err),
|
||||
},
|
||||
) from err
|
||||
|
||||
if not connectivity_ok:
|
||||
raise ConfigEntryNotReady(
|
||||
f"Unable to connect to Splunk instance at {host}:{port}"
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="cannot_connect",
|
||||
translation_placeholders={"host": host, "port": str(port)},
|
||||
)
|
||||
if not token_ok:
|
||||
raise ConfigEntryAuthFailed("Invalid Splunk token - please reauthenticate")
|
||||
raise ConfigEntryAuthFailed(
|
||||
translation_domain=DOMAIN, translation_key="invalid_auth"
|
||||
)
|
||||
|
||||
# Send startup event
|
||||
payload: dict[str, Any] = {
|
||||
|
||||
@@ -107,10 +107,7 @@ rules:
|
||||
status: exempt
|
||||
comment: |
|
||||
Integration does not create entities.
|
||||
exception-translations:
|
||||
status: todo
|
||||
comment: |
|
||||
Consider adding exception translations for user-facing errors beyond the current strings.json error section to provide more detailed translated error messages.
|
||||
exception-translations: done
|
||||
icon-translations:
|
||||
status: exempt
|
||||
comment: |
|
||||
|
||||
@@ -48,6 +48,23 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"exceptions": {
|
||||
"cannot_connect": {
|
||||
"message": "Unable to connect to Splunk at {host}:{port}."
|
||||
},
|
||||
"connection_error": {
|
||||
"message": "Unable to connect to Splunk at {host}:{port}: {error}."
|
||||
},
|
||||
"invalid_auth": {
|
||||
"message": "[%key:common::config_flow::error::invalid_auth%]"
|
||||
},
|
||||
"timeout_connect": {
|
||||
"message": "Connection to Splunk at {host}:{port} timed out."
|
||||
},
|
||||
"unexpected_error": {
|
||||
"message": "Unexpected error while connecting to Splunk at {host}:{port}: {error}."
|
||||
}
|
||||
},
|
||||
"issues": {
|
||||
"deprecated_yaml_import_issue_cannot_connect": {
|
||||
"description": "Configuring {integration_title} via YAML is deprecated and will be removed in a future release.\n\nWhile importing your configuration, a connection error occurred. Please correct your YAML configuration and restart Home Assistant, or remove the connection settings from your `{domain}:` configuration and configure the integration via the UI.\n\nNote: Entity filtering via YAML (`filter:`) will continue to work.",
|
||||
|
||||
@@ -41,12 +41,21 @@ async def test_setup_entry_success(
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("side_effect", "expected_state"),
|
||||
("side_effect", "expected_state", "expected_error_key"),
|
||||
[
|
||||
([False, False], ConfigEntryState.SETUP_RETRY),
|
||||
(ClientConnectionError("Connection failed"), ConfigEntryState.SETUP_RETRY),
|
||||
(TimeoutError(), ConfigEntryState.SETUP_RETRY),
|
||||
([True, False], ConfigEntryState.SETUP_ERROR),
|
||||
([False, False], ConfigEntryState.SETUP_RETRY, "cannot_connect"),
|
||||
(
|
||||
ClientConnectionError("Connection failed"),
|
||||
ConfigEntryState.SETUP_RETRY,
|
||||
"connection_error",
|
||||
),
|
||||
(TimeoutError(), ConfigEntryState.SETUP_RETRY, "timeout_connect"),
|
||||
(
|
||||
Exception("Unexpected error"),
|
||||
ConfigEntryState.SETUP_RETRY,
|
||||
"unexpected_error",
|
||||
),
|
||||
([True, False], ConfigEntryState.SETUP_ERROR, "invalid_auth"),
|
||||
],
|
||||
)
|
||||
async def test_setup_entry_error(
|
||||
@@ -55,6 +64,7 @@ async def test_setup_entry_error(
|
||||
mock_config_entry: MockConfigEntry,
|
||||
side_effect: Exception | list[bool],
|
||||
expected_state: ConfigEntryState,
|
||||
expected_error_key: str,
|
||||
) -> None:
|
||||
"""Test setup with various errors results in appropriate states."""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
@@ -65,6 +75,7 @@ async def test_setup_entry_error(
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert mock_config_entry.state is expected_state
|
||||
assert mock_config_entry.error_reason_translation_key == expected_error_key
|
||||
|
||||
|
||||
async def test_unload_entry(
|
||||
|
||||
Reference in New Issue
Block a user