diff --git a/clive/__private/core/commands/save_profile.py b/clive/__private/core/commands/save_profile.py index 31f7066181dd02c5c61181da108df8257ea73edf..dbe4d0a29e4402bfe465dca6e94c572a13f72a3c 100644 --- a/clive/__private/core/commands/save_profile.py +++ b/clive/__private/core/commands/save_profile.py @@ -1,9 +1,12 @@ from __future__ import annotations from dataclasses import dataclass -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Final -from clive.__private.core.commands.abc.command import Command +from beekeepy.exceptions import CommunicationError + +from clive.__private.core.beekeeper_manager import WalletsNotAvailableError +from clive.__private.core.commands.abc.command import Command, CommandError from clive.__private.core.commands.abc.command_encryption import CommandEncryption from clive.__private.core.encryption import EncryptionService from clive.__private.core.wallet_container import WalletContainer @@ -12,6 +15,13 @@ if TYPE_CHECKING: from clive.__private.core.profile import Profile +class ProfileSavingFailedError(CommandError): + MESSAGE: Final[str] = "Profile saving failed because beekeeper is not available." + + def __init__(self, command: Command) -> None: + super().__init__(command, self.MESSAGE) + + @dataclass(kw_only=True) class SaveProfile(CommandEncryption, Command): profile: Profile @@ -22,4 +32,7 @@ class SaveProfile(CommandEncryption, Command): async def _execute(self) -> None: encryption_service = EncryptionService(WalletContainer(self.unlocked_wallet, self.unlocked_encryption_wallet)) - await self.profile.save(encryption_service) + try: + await self.profile.save(encryption_service) + except (CommunicationError, WalletsNotAvailableError) as error: + raise ProfileSavingFailedError(self) from error diff --git a/clive/__private/core/error_handlers/general_error_notificator.py b/clive/__private/core/error_handlers/general_error_notificator.py index 8bce4a4999224ba05b6c53fc955a5ad0b5b79d7c..c10a940f9b5c20c7148c9dc26aaa44a3e9fb81f2 100644 --- a/clive/__private/core/error_handlers/general_error_notificator.py +++ b/clive/__private/core/error_handlers/general_error_notificator.py @@ -5,6 +5,7 @@ from typing import Final, TypeGuard from beekeepy.exceptions import InvalidPasswordError, NotExistingKeyError, NoWalletWithSuchNameError from clive.__private.core.commands.recover_wallets import CannotRecoverWalletsError +from clive.__private.core.commands.save_profile import ProfileSavingFailedError from clive.__private.core.error_handlers.abc.error_notificator import ErrorNotificator from clive.__private.storage.service import ProfileEncryptionError @@ -18,6 +19,7 @@ class GeneralErrorNotificator(ErrorNotificator[Exception]): NotExistingKeyError: "Key does not exist in the wallet.", ProfileEncryptionError: "Profile encryption failed which means profile cannot be saved or loaded.", CannotRecoverWalletsError: CannotRecoverWalletsError.MESSAGE, + ProfileSavingFailedError: ProfileSavingFailedError.MESSAGE, } def __init__(self) -> None: