Merge pull request #10121 from f321x/qml_create_storage_exc

wizard: raise more specific exc in create_storage() and pass some to crash reporter
This commit is contained in:
ghost43
2026-02-10 16:55:07 +00:00
committed by GitHub
3 changed files with 33 additions and 23 deletions
+6 -2
View File
@@ -3,11 +3,12 @@ from typing import TYPE_CHECKING
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:
@@ -172,9 +173,12 @@ class QENewWalletWizard(NewWalletWizard, QEAbstractWizard):
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):
+9 -7
View File
@@ -70,7 +70,7 @@ from electrum.i18n import _, set_language
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
@@ -411,12 +411,14 @@ class ElectrumGui(BaseElectrumGui, Logger):
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)
else:
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.
+18 -14
View File
@@ -12,7 +12,8 @@ from electrum.logging import get_logger
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
@@ -684,8 +685,11 @@ class NewWalletWizard(KeystoreWizard):
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
@@ -729,35 +733,35 @@ class NewWalletWizard(KeystoreWizard):
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 TypeError(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 TypeError(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():
@@ -792,16 +796,16 @@ class NewWalletWizard(KeystoreWizard):
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())