1
0
mirror of https://github.com/home-assistant/core.git synced 2026-04-17 15:44:52 +01:00

Remove redundant exception messages from Telegram bot (#164289)

This commit is contained in:
hanwg
2026-02-27 15:19:10 +08:00
committed by GitHub
parent 37d2c946e8
commit e63e54820c
2 changed files with 31 additions and 23 deletions

View File

@@ -1080,7 +1080,6 @@ async def load_data(
req = await client.get(url)
except (httpx.HTTPError, httpx.InvalidURL) as err:
raise HomeAssistantError(
f"Failed to load URL: {err!s}",
translation_domain=DOMAIN,
translation_key="failed_to_load_url",
translation_placeholders={"error": str(err)},
@@ -1107,7 +1106,6 @@ async def load_data(
1
) # Add a sleep to allow other async operations to proceed
raise HomeAssistantError(
f"Failed to load URL: {req.status_code}",
translation_domain=DOMAIN,
translation_key="failed_to_load_url",
translation_placeholders={"error": str(req.status_code)},
@@ -1117,13 +1115,11 @@ async def load_data(
return await hass.async_add_executor_job(_read_file_as_bytesio, filepath)
raise ServiceValidationError(
"File path has not been configured in allowlist_external_dirs.",
translation_domain=DOMAIN,
translation_key="allowlist_external_dirs_error",
)
else:
raise ServiceValidationError(
"URL or File is required.",
translation_domain=DOMAIN,
translation_key="missing_input",
translation_placeholders={"field": "URL or File"},
@@ -1138,7 +1134,6 @@ def _validate_credentials_input(
and not username
):
raise ServiceValidationError(
"Username is required.",
translation_domain=DOMAIN,
translation_key="missing_input",
translation_placeholders={"field": "Username"},
@@ -1154,7 +1149,6 @@ def _validate_credentials_input(
and not password
):
raise ServiceValidationError(
"Password is required.",
translation_domain=DOMAIN,
translation_key="missing_input",
translation_placeholders={"field": "Password"},
@@ -1170,7 +1164,6 @@ def _read_file_as_bytesio(file_path: str) -> io.BytesIO:
return data
except OSError as err:
raise HomeAssistantError(
f"Failed to load file: {err!s}",
translation_domain=DOMAIN,
translation_key="failed_to_load_file",
translation_placeholders={"error": str(err)},

View File

@@ -1443,10 +1443,9 @@ async def test_send_video(
)
await hass.async_block_till_done()
assert (
err.value.args[0]
== "File path has not been configured in allowlist_external_dirs."
)
assert err.value.translation_domain == DOMAIN
assert err.value.translation_key == "allowlist_external_dirs_error"
# test: missing username input
@@ -1463,7 +1462,10 @@ async def test_send_video(
)
await hass.async_block_till_done()
assert err.value.args[0] == "Username is required."
assert err.value.translation_domain == DOMAIN
assert err.value.translation_key == "missing_input"
assert err.value.translation_placeholders == {"field": "Username"}
# test: missing password input
@@ -1479,7 +1481,10 @@ async def test_send_video(
)
await hass.async_block_till_done()
assert err.value.args[0] == "Password is required."
assert err.value.translation_domain == DOMAIN
assert err.value.translation_key == "missing_input"
assert err.value.translation_placeholders == {"field": "Password"}
# test: 404 error
@@ -1502,8 +1507,11 @@ async def test_send_video(
)
await hass.async_block_till_done()
assert mock_get.call_count > 0
assert err.value.args[0] == "Failed to load URL: 404"
assert err.value.translation_domain == DOMAIN
assert err.value.translation_key == "failed_to_load_url"
assert err.value.translation_placeholders == {"error": "404"}
# test: invalid url
@@ -1521,11 +1529,13 @@ async def test_send_video(
)
await hass.async_block_till_done()
assert mock_get.call_count > 0
assert (
err.value.args[0]
== "Failed to load URL: Request URL is missing an 'http://' or 'https://' protocol."
)
assert err.value.translation_domain == DOMAIN
assert err.value.translation_key == "failed_to_load_url"
assert err.value.translation_placeholders == {
"error": "Request URL is missing an 'http://' or 'https://' protocol."
}
# test: no url/file input
@@ -1538,7 +1548,10 @@ async def test_send_video(
)
await hass.async_block_till_done()
assert err.value.args[0] == "URL or File is required."
assert err.value.translation_domain == DOMAIN
assert err.value.translation_key == "missing_input"
assert err.value.translation_placeholders == {"field": "URL or File"}
# test: load file error (e.g. not found, permissions error)
@@ -1555,10 +1568,12 @@ async def test_send_video(
)
await hass.async_block_till_done()
assert (
err.value.args[0]
== "Failed to load file: [Errno 2] No such file or directory: '/tmp/not-exists'"
)
assert err.value.translation_domain == DOMAIN
assert err.value.translation_key == "failed_to_load_file"
assert err.value.translation_placeholders == {
"error": "[Errno 2] No such file or directory: '/tmp/not-exists'"
}
# test: success with file
write_utf8_file("/tmp/mock", "mock file contents") # noqa: S108