add InvalidPasswordError handling to more places

This commit is contained in:
Lex Berezhny 2019-12-08 21:55:51 -05:00
parent 75d78bfa53
commit 94a41270d0
4 changed files with 5 additions and 12 deletions

View file

@ -1,2 +1,2 @@
class BaseError(Exception): class BaseError(Exception):
log_level = 50 pass

View file

@ -599,14 +599,6 @@ class Daemon(metaclass=JSONRPCServerType):
except asyncio.CancelledError: except asyncio.CancelledError:
log.info("cancelled API call for: %s", function_name) log.info("cancelled API call for: %s", function_name)
raise raise
except BaseError as e:
if log.isEnabledFor(e.log_level):
log.exception("SDK generated the following exception:")
return JSONRPCError(
f"Error calling {function_name} with args {args}\n" + str(e),
JSONRPCError.CODE_APPLICATION_ERROR,
format_exc()
)
except Exception as e: # pylint: disable=broad-except except Exception as e: # pylint: disable=broad-except
log.exception("error handling api request") log.exception("error handling api request")
return JSONRPCError( return JSONRPCError(

View file

@ -2,9 +2,9 @@ import asyncio
import json import json
from torba.client.wallet import ENCRYPT_ON_DISK from torba.client.wallet import ENCRYPT_ON_DISK
from torba.client.errors import InvalidPasswordError
from lbry.testcase import CommandTestCase from lbry.testcase import CommandTestCase
from lbry.wallet.dewies import dict_values_to_lbc from lbry.wallet.dewies import dict_values_to_lbc
from lbry.error import InvalidPasswordError
class WalletCommands(CommandTestCase): class WalletCommands(CommandTestCase):

View file

@ -10,6 +10,7 @@ from torba.client.mnemonic import Mnemonic
from torba.client.bip32 import PrivateKey, PubKey, from_extended_key_string from torba.client.bip32 import PrivateKey, PubKey, from_extended_key_string
from torba.client.hash import aes_encrypt, aes_decrypt, sha256 from torba.client.hash import aes_encrypt, aes_decrypt, sha256
from torba.client.constants import COIN from torba.client.constants import COIN
from torba.client.errors import InvalidPasswordError
if typing.TYPE_CHECKING: if typing.TYPE_CHECKING:
from torba.client import baseledger, wallet as basewallet from torba.client import baseledger, wallet as basewallet
@ -349,11 +350,11 @@ class BaseAccount:
assert self.encrypted, "Key is not encrypted." assert self.encrypted, "Key is not encrypted."
try: try:
seed = self._decrypt_seed(password) seed = self._decrypt_seed(password)
except ValueError: except (ValueError, InvalidPasswordError):
return False return False
try: try:
private_key = self._decrypt_private_key_string(password) private_key = self._decrypt_private_key_string(password)
except (TypeError, ValueError): except (TypeError, ValueError, InvalidPasswordError):
return False return False
self.seed = seed self.seed = seed
self.private_key = private_key self.private_key = private_key