Don't log errors when raising a backup exception in Google Drive (#136916)

This commit is contained in:
tronikos 2025-01-30 09:15:13 -08:00 committed by GitHub
parent f501b55aed
commit 3dc52774fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 12 deletions

View File

@ -80,16 +80,14 @@ class GoogleDriveBackupAgent(BackupAgent):
try: try:
await self._client.async_upload_backup(open_stream, backup) await self._client.async_upload_backup(open_stream, backup)
except (GoogleDriveApiError, HomeAssistantError, TimeoutError) as err: except (GoogleDriveApiError, HomeAssistantError, TimeoutError) as err:
_LOGGER.error("Upload backup error: %s", err) raise BackupAgentError(f"Failed to upload backup: {err}") from err
raise BackupAgentError("Failed to upload backup") from err
async def async_list_backups(self, **kwargs: Any) -> list[AgentBackup]: async def async_list_backups(self, **kwargs: Any) -> list[AgentBackup]:
"""List backups.""" """List backups."""
try: try:
return await self._client.async_list_backups() return await self._client.async_list_backups()
except (GoogleDriveApiError, HomeAssistantError, TimeoutError) as err: except (GoogleDriveApiError, HomeAssistantError, TimeoutError) as err:
_LOGGER.error("List backups error: %s", err) raise BackupAgentError(f"Failed to list backups: {err}") from err
raise BackupAgentError("Failed to list backups") from err
async def async_get_backup( async def async_get_backup(
self, self,
@ -121,9 +119,7 @@ class GoogleDriveBackupAgent(BackupAgent):
stream = await self._client.async_download(file_id) stream = await self._client.async_download(file_id)
return ChunkAsyncStreamIterator(stream) return ChunkAsyncStreamIterator(stream)
except (GoogleDriveApiError, HomeAssistantError, TimeoutError) as err: except (GoogleDriveApiError, HomeAssistantError, TimeoutError) as err:
_LOGGER.error("Download backup error: %s", err) raise BackupAgentError(f"Failed to download backup: {err}") from err
raise BackupAgentError("Failed to download backup") from err
_LOGGER.error("Download backup_id: %s not found", backup_id)
raise BackupAgentError("Backup not found") raise BackupAgentError("Backup not found")
async def async_delete_backup( async def async_delete_backup(
@ -143,5 +139,4 @@ class GoogleDriveBackupAgent(BackupAgent):
await self._client.async_delete(file_id) await self._client.async_delete(file_id)
_LOGGER.debug("Deleted backup_id: %s", backup_id) _LOGGER.debug("Deleted backup_id: %s", backup_id)
except (GoogleDriveApiError, HomeAssistantError, TimeoutError) as err: except (GoogleDriveApiError, HomeAssistantError, TimeoutError) as err:
_LOGGER.error("Delete backup error: %s", err) raise BackupAgentError(f"Failed to delete backup: {err}") from err
raise BackupAgentError("Failed to delete backup") from err

View File

@ -141,7 +141,7 @@ async def test_agents_list_backups_fail(
assert response["success"] assert response["success"]
assert response["result"]["backups"] == [] assert response["result"]["backups"] == []
assert response["result"]["agent_errors"] == { assert response["result"]["agent_errors"] == {
TEST_AGENT_ID: "Failed to list backups" TEST_AGENT_ID: "Failed to list backups: some error"
} }
@ -381,7 +381,7 @@ async def test_agents_upload_fail(
await hass.async_block_till_done() await hass.async_block_till_done()
assert resp.status == 201 assert resp.status == 201
assert "Upload backup error: some error" in caplog.text assert "Failed to upload backup: some error" in caplog.text
async def test_agents_delete( async def test_agents_delete(
@ -430,7 +430,7 @@ async def test_agents_delete_fail(
assert response["success"] assert response["success"]
assert response["result"] == { assert response["result"] == {
"agent_errors": {TEST_AGENT_ID: "Failed to delete backup"} "agent_errors": {TEST_AGENT_ID: "Failed to delete backup: some error"}
} }