mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Simplify error handling in BackupAgent when a backup is not found (#139754)
Simplify error handling in BackupAgent when backup is not found
This commit is contained in:
@@ -64,6 +64,7 @@ from .models import (
|
||||
AgentBackup,
|
||||
BackupError,
|
||||
BackupManagerError,
|
||||
BackupNotFound,
|
||||
BackupReaderWriterError,
|
||||
BaseBackup,
|
||||
Folder,
|
||||
@@ -648,6 +649,8 @@ class BackupManager:
|
||||
)
|
||||
for idx, result in enumerate(get_backup_results):
|
||||
agent_id = agent_ids[idx]
|
||||
if isinstance(result, BackupNotFound):
|
||||
continue
|
||||
if isinstance(result, BackupAgentError):
|
||||
agent_errors[agent_id] = result
|
||||
continue
|
||||
@@ -659,6 +662,8 @@ class BackupManager:
|
||||
continue
|
||||
if isinstance(result, BaseException):
|
||||
raise result # unexpected error
|
||||
# Check for None to be backwards compatible with the old BackupAgent API,
|
||||
# this can be removed in HA Core 2025.10
|
||||
if not result:
|
||||
continue
|
||||
if backup is None:
|
||||
@@ -723,6 +728,8 @@ class BackupManager:
|
||||
)
|
||||
for idx, result in enumerate(delete_backup_results):
|
||||
agent_id = agent_ids[idx]
|
||||
if isinstance(result, BackupNotFound):
|
||||
continue
|
||||
if isinstance(result, BackupAgentError):
|
||||
agent_errors[agent_id] = result
|
||||
continue
|
||||
@@ -832,7 +839,7 @@ class BackupManager:
|
||||
agent_errors = {
|
||||
backup_id: error
|
||||
for backup_id, error in zip(backup_ids, delete_results, strict=True)
|
||||
if error
|
||||
if error and not isinstance(error, BackupNotFound)
|
||||
}
|
||||
if agent_errors:
|
||||
LOGGER.error(
|
||||
@@ -1264,7 +1271,15 @@ class BackupManager:
|
||||
) -> None:
|
||||
"""Initiate restoring a backup."""
|
||||
agent = self.backup_agents[agent_id]
|
||||
if not await agent.async_get_backup(backup_id):
|
||||
try:
|
||||
backup = await agent.async_get_backup(backup_id)
|
||||
except BackupNotFound as err:
|
||||
raise BackupManagerError(
|
||||
f"Backup {backup_id} not found in agent {agent_id}"
|
||||
) from err
|
||||
# Check for None to be backwards compatible with the old BackupAgent API,
|
||||
# this can be removed in HA Core 2025.10
|
||||
if not backup:
|
||||
raise BackupManagerError(
|
||||
f"Backup {backup_id} not found in agent {agent_id}"
|
||||
)
|
||||
@@ -1352,7 +1367,15 @@ class BackupManager:
|
||||
agent = self.backup_agents[agent_id]
|
||||
except KeyError as err:
|
||||
raise BackupManagerError(f"Invalid agent selected: {agent_id}") from err
|
||||
if not await agent.async_get_backup(backup_id):
|
||||
try:
|
||||
backup = await agent.async_get_backup(backup_id)
|
||||
except BackupNotFound as err:
|
||||
raise BackupManagerError(
|
||||
f"Backup {backup_id} not found in agent {agent_id}"
|
||||
) from err
|
||||
# Check for None to be backwards compatible with the old BackupAgent API,
|
||||
# this can be removed in HA Core 2025.10
|
||||
if not backup:
|
||||
raise BackupManagerError(
|
||||
f"Backup {backup_id} not found in agent {agent_id}"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user