Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions electrum/gui/qml/qewizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@

from PyQt6.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject

from electrum.base_crash_reporter import send_exception_to_crash_reporter
from electrum.logging import get_logger
from electrum import mnemonic
from electrum.wizard import NewWalletWizard, ServerConnectWizard, TermsOfUseWizard
from electrum.storage import WalletStorage, StorageReadWriteError
from electrum.util import WalletFileException
from electrum.util import WalletFileException, UserFacingException
from electrum.gui import messages

if TYPE_CHECKING:
Expand Down Expand Up @@ -172,9 +173,12 @@ def createStorage(self, js_data, single_password_enabled, single_password):
self.path = path

self.createSuccess.emit()
except UserFacingException as e:
self._logger.debug(f"createStorage errored: {e!r}", exc_info=True)
self.createError.emit(str(e))
except Exception as e:
self._logger.exception(f"createStorage errored: {e!r}")
self.createError.emit(str(e))
send_exception_to_crash_reporter(e)


class QEServerConnectWizard(ServerConnectWizard, QEAbstractWizard):
Expand Down
17 changes: 10 additions & 7 deletions electrum/gui/qt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
from electrum.plugin import run_hook
from electrum.util import (UserCancelled, profiler, send_exception_to_crash_reporter,
WalletFileException, get_new_wallet_name, InvalidPassword,
standardize_path)
standardize_path, UserFacingException)
from electrum.wallet import Wallet, Abstract_Wallet
from electrum.wallet_db import WalletRequiresSplit, WalletRequiresUpgrade, WalletUnfinished
from electrum.gui import BaseElectrumGui
Expand Down Expand Up @@ -411,12 +411,15 @@ def start_new_window(
return
except Exception as e:
self.logger.exception('')
err_text = str(e) if isinstance(e, WalletFileException) else repr(e)
custom_message_box(icon=QMessageBox.Icon.Warning,
parent=None,
title=_('Error'),
text=_('Cannot load wallet') + '(2) :\n' + err_text)
if isinstance(e, WalletFileException) and e.should_report_crash:
if isinstance(e, UserFacingException) \
or isinstance(e, WalletFileException) and not e.should_report_crash:
err_text = str(e) if isinstance(e, WalletFileException) else repr(e)
custom_message_box(icon=QMessageBox.Icon.Warning,
parent=None,
title=_('Error'),
text=_('Cannot load wallet') + '(2) :\n' + err_text)
elif isinstance(e, WalletFileException) and e.should_report_crash \
or not isinstance(e, WalletFileException):
send_exception_to_crash_reporter(e)
if app_is_starting:
# If we raise in this context, there are no more fallbacks, we will shut down.
Expand Down
32 changes: 18 additions & 14 deletions electrum/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
from electrum.network import ProxySettings
from electrum.plugin import run_hook
from electrum.slip39 import EncryptedSeed
from electrum.storage import WalletStorage, StorageEncryptionVersion
from electrum.storage import WalletStorage, StorageEncryptionVersion, StorageReadWriteError
from electrum.util import UserFacingException
from electrum.wallet_db import WalletDB
from electrum.bip32 import normalize_bip32_derivation, xpub_type
from electrum import keystore, mnemonic, bitcoin
Expand Down Expand Up @@ -661,8 +662,11 @@ def create_storage(self, path: str, data: dict):
assert data['wallet_type'] in ['standard', '2fa', 'imported', 'multisig']

if os.path.exists(path):
raise Exception('file already exists at path')
storage = WalletStorage(path)
raise UserFacingException(_('File already exists at path: {}').format(path))
try:
storage = WalletStorage(path)
except StorageReadWriteError as e:
raise UserFacingException(e)

# TODO: refactor using self.keystore_from_data
k = None
Expand Down Expand Up @@ -701,35 +705,35 @@ def create_storage(self, path: str, data: dict):
self._logger.debug('creating keystore from 2fa seed')
k = keystore.from_xprv(data['x1']['xprv'])
else:
raise Exception('unsupported/unknown seed_type %s' % data['seed_type'])
raise NotImplementedError('unsupported/unknown seed_type %s' % data['seed_type'])
elif data['keystore_type'] == 'masterkey':
k = keystore.from_master_key(data['master_key'])
if isinstance(k, keystore.Xpub): # has xpub
t1 = xpub_type(k.xpub)
if data['wallet_type'] == 'multisig':
if t1 not in ['standard', 'p2wsh', 'p2wsh-p2sh']:
raise Exception('wrong key type %s' % t1)
raise UserFacingException(_('Wrong key type {}').format(t1))
else:
if t1 not in ['standard', 'p2wpkh', 'p2wpkh-p2sh']:
raise Exception('wrong key type %s' % t1)
raise UserFacingException(_('Wrong key type {}').format(t1))
elif isinstance(k, keystore.Old_KeyStore):
pass
else:
raise Exception(f'unexpected keystore type: {type(k)}')
raise NotImplementedError(f'unexpected keystore type: {type(k)}')
elif data['keystore_type'] == 'hardware':
k = self.hw_keystore(data)
if isinstance(k, keystore.Xpub): # has xpub
t1 = xpub_type(k.xpub)
if data['wallet_type'] == 'multisig':
if t1 not in ['standard', 'p2wsh', 'p2wsh-p2sh']:
raise Exception('wrong key type %s' % t1)
raise UserFacingException(_('Wrong key type {}').format(t1))
else:
if t1 not in ['standard', 'p2wpkh', 'p2wpkh-p2sh']:
raise Exception('wrong key type %s' % t1)
raise UserFacingException(_('Wrong key type {}').format(t1))
else:
raise Exception(f'unexpected keystore type: {type(k)}')
raise NotImplementedError(f'unexpected keystore type: {type(k)}')
else:
raise Exception('unsupported/unknown keystore_type %s' % data['keystore_type'])
raise NotImplementedError('unsupported/unknown keystore_type %s' % data['keystore_type'])

if data['password']:
if k and k.may_have_password():
Expand Down Expand Up @@ -764,16 +768,16 @@ def create_storage(self, path: str, data: dict):
db.put('use_trustedcoin', True)
elif data['wallet_type'] == 'multisig':
if not isinstance(k, keystore.Xpub):
raise Exception(f'unexpected keystore(main) type={type(k)} in multisig. not bip32.')
raise TypeError(f'unexpected keystore(main) type={type(k)} in multisig. not bip32.')
k_xpub_type = xpub_type(k.xpub)
db.put('wallet_type', '%dof%d' % (data['multisig_signatures'], data['multisig_participants']))
db.put('x1', k.dump())
for cosigner in data['multisig_cosigner_data']:
cosigner_keystore = self.keystore_from_data('multisig', data['multisig_cosigner_data'][cosigner])
if not isinstance(cosigner_keystore, keystore.Xpub):
raise Exception(f'unexpected keystore(cosigner) type={type(cosigner_keystore)} in multisig. not bip32.')
raise TypeError(f'unexpected keystore(cosigner) type={type(cosigner_keystore)} in multisig. not bip32.')
if k_xpub_type != xpub_type(cosigner_keystore.xpub):
raise Exception('multisig wallet needs to have homogeneous xpub types')
raise UserFacingException(_('Multisig wallet needs to have homogeneous xpub types.'))
if data['encrypt'] and cosigner_keystore.may_have_password():
cosigner_keystore.update_password(None, data['password'])
db.put(f'x{cosigner}', cosigner_keystore.dump())
Expand Down