Skip to content
Snippets Groups Projects
Commit afdc12a1 authored by Marcin Sobczyk's avatar Marcin Sobczyk
Browse files

Display meaningful notofication when save profile fails

parent 3ba929a1
No related branches found
No related tags found
2 merge requests!600v1.27.5.21 Release,!593msobczyk/371 change moment of saving changes to profile
from __future__ import annotations from __future__ import annotations
from dataclasses import dataclass 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.commands.abc.command_encryption import CommandEncryption
from clive.__private.core.encryption import EncryptionService from clive.__private.core.encryption import EncryptionService
from clive.__private.core.wallet_container import WalletContainer from clive.__private.core.wallet_container import WalletContainer
...@@ -12,6 +15,13 @@ if TYPE_CHECKING: ...@@ -12,6 +15,13 @@ if TYPE_CHECKING:
from clive.__private.core.profile import Profile 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) @dataclass(kw_only=True)
class SaveProfile(CommandEncryption, Command): class SaveProfile(CommandEncryption, Command):
profile: Profile profile: Profile
...@@ -22,4 +32,7 @@ class SaveProfile(CommandEncryption, Command): ...@@ -22,4 +32,7 @@ class SaveProfile(CommandEncryption, Command):
async def _execute(self) -> None: async def _execute(self) -> None:
encryption_service = EncryptionService(WalletContainer(self.unlocked_wallet, self.unlocked_encryption_wallet)) 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
...@@ -5,6 +5,7 @@ from typing import Final, TypeGuard ...@@ -5,6 +5,7 @@ from typing import Final, TypeGuard
from beekeepy.exceptions import InvalidPasswordError, NotExistingKeyError, NoWalletWithSuchNameError from beekeepy.exceptions import InvalidPasswordError, NotExistingKeyError, NoWalletWithSuchNameError
from clive.__private.core.commands.recover_wallets import CannotRecoverWalletsError 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.core.error_handlers.abc.error_notificator import ErrorNotificator
from clive.__private.storage.service import ProfileEncryptionError from clive.__private.storage.service import ProfileEncryptionError
...@@ -18,6 +19,7 @@ class GeneralErrorNotificator(ErrorNotificator[Exception]): ...@@ -18,6 +19,7 @@ class GeneralErrorNotificator(ErrorNotificator[Exception]):
NotExistingKeyError: "Key does not exist in the wallet.", NotExistingKeyError: "Key does not exist in the wallet.",
ProfileEncryptionError: "Profile encryption failed which means profile cannot be saved or loaded.", ProfileEncryptionError: "Profile encryption failed which means profile cannot be saved or loaded.",
CannotRecoverWalletsError: CannotRecoverWalletsError.MESSAGE, CannotRecoverWalletsError: CannotRecoverWalletsError.MESSAGE,
ProfileSavingFailedError: ProfileSavingFailedError.MESSAGE,
} }
def __init__(self) -> None: def __init__(self) -> None:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment