tchange many str(e) to repr(e) as some exceptions were cryptic - electrum - Electrum Bitcoin wallet
HTML git clone https://git.parazyd.org/electrum
DIR Log
DIR Files
DIR Refs
DIR Submodules
---
DIR commit f60f690ca944b9611a6cbf7b29a8a8aab5f13b21
DIR parent 40e2b1d6e72fff3b05969e146ccaca89beb83e2c
HTML Author: SomberNight <somber.night@protonmail.com>
Date: Wed, 17 Jul 2019 20:12:52 +0200
change many str(e) to repr(e) as some exceptions were cryptic
it's often valuable to see the type of the exception
(especially as for some exceptions str(e) == '')
Diffstat:
M electrum/commands.py | 2 +-
M electrum/dnssec.py | 2 +-
M electrum/gui/kivy/uix/screens.py | 4 ++--
M electrum/gui/qt/__init__.py | 6 +++---
M electrum/gui/qt/address_dialog.py | 2 +-
M electrum/gui/qt/installwizard.py | 4 ++--
M electrum/gui/qt/main_window.py | 26 +++++++++++++-------------
M electrum/gui/qt/qrtextedit.py | 4 ++--
M electrum/gui/qt/transaction_dialog… | 2 +-
M electrum/gui/stdio.py | 2 +-
M electrum/gui/text.py | 2 +-
M electrum/jsonrpc.py | 4 ++--
M electrum/plugin.py | 2 +-
M electrum/plugins/cosigner_pool/qt.… | 4 ++--
M electrum/plugins/email_requests/qt… | 4 ++--
M electrum/plugins/greenaddress_inst… | 2 +-
M electrum/plugins/keepkey/keepkey.py | 2 +-
M electrum/plugins/labels/labels.py | 2 +-
M electrum/plugins/ledger/qt.py | 2 +-
M electrum/plugins/safe_t/safe_t.py | 2 +-
M electrum/plugins/trezor/trezor.py | 2 +-
M electrum/plugins/trustedcoin/kivy.… | 2 +-
M electrum/plugins/trustedcoin/qt.py | 4 ++--
M electrum/plugins/trustedcoin/trust… | 4 ++--
M electrum/synchronizer.py | 2 +-
M electrum/verifier.py | 2 +-
26 files changed, 48 insertions(+), 48 deletions(-)
---
DIR diff --git a/electrum/commands.py b/electrum/commands.py
t@@ -415,7 +415,7 @@ class Commands:
addr = self.wallet.import_private_key(privkey, password)
out = "Keypair imported: " + addr
except Exception as e:
- out = "Error: " + str(e)
+ out = "Error: " + repr(e)
return out
def _resolver(self, x):
DIR diff --git a/electrum/dnssec.py b/electrum/dnssec.py
t@@ -265,7 +265,7 @@ def query(url, rtype):
out = get_and_validate(ns, url, rtype)
validated = True
except BaseException as e:
- _logger.info(f"DNSSEC error: {str(e)}")
+ _logger.info(f"DNSSEC error: {repr(e)}")
resolver = dns.resolver.get_default_resolver()
out = resolver.query(url, rtype)
validated = False
DIR diff --git a/electrum/gui/kivy/uix/screens.py b/electrum/gui/kivy/uix/screens.py
t@@ -290,7 +290,7 @@ class SendScreen(CScreen):
return
except Exception as e:
traceback.print_exc(file=sys.stdout)
- self.app.show_error(str(e))
+ self.app.show_error(repr(e))
return
if rbf:
tx.set_rbf(True)
t@@ -410,7 +410,7 @@ class ReceiveScreen(CScreen):
self.app.wallet.add_payment_request(req, self.app.electrum_config)
added_request = True
except Exception as e:
- self.app.show_error(_('Error adding payment request') + ':\n' + str(e))
+ self.app.show_error(_('Error adding payment request') + ':\n' + repr(e))
added_request = False
finally:
self.app.update_tab('requests')
DIR diff --git a/electrum/gui/qt/__init__.py b/electrum/gui/qt/__init__.py
t@@ -230,7 +230,7 @@ class ElectrumGui(Logger):
custom_message_box(icon=QMessageBox.Warning,
parent=None,
title=_('Error'),
- text=_('Cannot load wallet') + ' (1):\n' + str(e))
+ text=_('Cannot load wallet') + ' (1):\n' + repr(e))
# if app is starting, still let wizard to appear
if not app_is_starting:
return
t@@ -242,7 +242,7 @@ class ElectrumGui(Logger):
custom_message_box(icon=QMessageBox.Warning,
parent=None,
title=_('Error'),
- text=_('Cannot load wallet') + ' (2):\n' + str(e))
+ text=_('Cannot load wallet') + ' (2):\n' + repr(e))
if not wallet:
return
# create or raise window
t@@ -257,7 +257,7 @@ class ElectrumGui(Logger):
custom_message_box(icon=QMessageBox.Warning,
parent=None,
title=_('Error'),
- text=_('Cannot create window for wallet') + ':\n' + str(e))
+ text=_('Cannot create window for wallet') + ':\n' + repr(e))
if app_is_starting:
wallet_dir = os.path.dirname(path)
path = os.path.join(wallet_dir, get_new_wallet_name(wallet_dir))
DIR diff --git a/electrum/gui/qt/address_dialog.py b/electrum/gui/qt/address_dialog.py
t@@ -99,4 +99,4 @@ class AddressDialog(WindowModalDialog):
try:
self.parent.show_qrcode(text, 'Address', parent=self)
except Exception as e:
- self.show_message(str(e))
+ self.show_message(repr(e))
DIR diff --git a/electrum/gui/qt/installwizard.py b/electrum/gui/qt/installwizard.py
t@@ -265,7 +265,7 @@ class InstallWizard(QDialog, MessageBoxMixin, BaseWizard):
continue
except BaseException as e:
self.logger.exception('')
- self.show_message(title=_('Error'), msg=str(e))
+ self.show_message(title=_('Error'), msg=repr(e))
raise UserCancelled()
elif self.temp_storage.is_encrypted_with_hw_device():
try:
t@@ -278,7 +278,7 @@ class InstallWizard(QDialog, MessageBoxMixin, BaseWizard):
return self.select_storage(path, get_wallet_from_daemon)
except BaseException as e:
self.logger.exception('')
- self.show_message(title=_('Error'), msg=str(e))
+ self.show_message(title=_('Error'), msg=repr(e))
raise UserCancelled()
if self.temp_storage.is_past_initial_decryption():
break
DIR diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py
t@@ -345,7 +345,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
self.logger.error("on_error", exc_info=exc_info)
except OSError:
pass # see #4418
- self.show_error(str(e))
+ self.show_error(repr(e))
def on_network(self, event, *args):
if event == 'wallet_updated':
t@@ -1026,7 +1026,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
try:
self.wallet.sign_payment_request(addr, alias, alias_addr, password)
except Exception as e:
- self.show_error(str(e))
+ self.show_error(repr(e))
return
else:
return
t@@ -1045,7 +1045,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
self.wallet.add_payment_request(req, self.config)
except Exception as e:
self.logger.exception('Error adding payment request')
- self.show_error(_('Error adding payment request') + ':\n' + str(e))
+ self.show_error(_('Error adding payment request') + ':\n' + repr(e))
else:
self.sign_payment_request(addr)
self.save_request_button.setEnabled(False)
t@@ -2151,7 +2151,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
return
except BaseException as e:
self.logger.exception('')
- self.show_error(str(e))
+ self.show_error(repr(e))
return
old_password = hw_dev_pw if self.wallet.has_password() else None
new_password = hw_dev_pw if encrypt_file else None
t@@ -2288,7 +2288,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
seed = keystore.get_seed(password)
passphrase = keystore.get_passphrase(password)
except BaseException as e:
- self.show_error(str(e))
+ self.show_error(repr(e))
return
from .seed_dialog import SeedDialog
d = SeedDialog(self, seed, passphrase)
t@@ -2308,7 +2308,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
pk, redeem_script = self.wallet.export_private_key(address, password)
except Exception as e:
self.logger.exception('')
- self.show_message(str(e))
+ self.show_message(repr(e))
return
xtype = bitcoin.deserialize_privkey(pk)[0]
d = WindowModalDialog(self, _("Private key"))
t@@ -2502,7 +2502,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
tx = tx_from_str(txt)
return Transaction(tx)
except BaseException as e:
- self.show_critical(_("Electrum was unable to parse your transaction") + ":\n" + str(e))
+ self.show_critical(_("Electrum was unable to parse your transaction") + ":\n" + repr(e))
return
def read_tx_from_qrcode(self):
t@@ -2510,7 +2510,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
try:
data = qrscanner.scan_barcode(self.config.get_video_device())
except BaseException as e:
- self.show_error(str(e))
+ self.show_error(repr(e))
return
if not data:
return
t@@ -2563,7 +2563,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
raw_tx = self.network.run_from_another_thread(
self.network.get_transaction(txid, timeout=10))
except Exception as e:
- self.show_message(_("Error getting transaction from network") + ":\n" + str(e))
+ self.show_message(_("Error getting transaction from network") + ":\n" + repr(e))
return
tx = transaction.Transaction(raw_tx)
self.show_transaction(tx)
t@@ -2655,7 +2655,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
self.show_critical(txt, title=_("Unable to create csv"))
except Exception as e:
- self.show_message(str(e))
+ self.show_message(repr(e))
return
self.show_message(_("Private keys exported."))
t@@ -2732,7 +2732,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
try:
valid_privkeys = get_pk(raise_on_error=True) is not None
except Exception as e:
- button.setToolTip(f'{_("Error")}: {str(e)}')
+ button.setToolTip(f'{_("Error")}: {repr(e)}')
else:
button.setToolTip('')
button.setEnabled(get_address() is not None and valid_privkeys)
t@@ -2753,7 +2753,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
try:
coins, keypairs = sweep_preparations(get_pk(), self.network)
except Exception as e: # FIXME too broad...
- self.show_message(str(e))
+ self.show_message(repr(e))
return
self.do_clear()
self.tx_external_keypairs = keypairs
t@@ -2946,7 +2946,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
SSL_error = None
except BaseException as e:
SSL_identity = "error"
- SSL_error = str(e)
+ SSL_error = repr(e)
else:
SSL_identity = ""
SSL_error = None
DIR diff --git a/electrum/gui/qt/qrtextedit.py b/electrum/gui/qt/qrtextedit.py
t@@ -49,7 +49,7 @@ class ScanQRTextEdit(ButtonsTextEdit, MessageBoxMixin):
with open(fileName, "r") as f:
data = f.read()
except BaseException as e:
- self.show_error(_('Error opening file') + ':\n' + str(e))
+ self.show_error(_('Error opening file') + ':\n' + repr(e))
else:
self.setText(data)
t@@ -58,7 +58,7 @@ class ScanQRTextEdit(ButtonsTextEdit, MessageBoxMixin):
try:
data = qrscanner.scan_barcode(get_config().get_video_device())
except BaseException as e:
- self.show_error(str(e))
+ self.show_error(repr(e))
data = ''
if not data:
data = ''
DIR diff --git a/electrum/gui/qt/transaction_dialog.py b/electrum/gui/qt/transaction_dialog.py
t@@ -191,7 +191,7 @@ class TxDialog(QDialog, MessageBoxMixin):
self.show_error(_('Failed to display QR code.') + '\n' +
_('Transaction is too large in size.'))
except Exception as e:
- self.show_error(_('Failed to display QR code.') + '\n' + str(e))
+ self.show_error(_('Failed to display QR code.') + '\n' + repr(e))
def sign(self):
def sign_done(success):
DIR diff --git a/electrum/gui/stdio.py b/electrum/gui/stdio.py
t@@ -199,7 +199,7 @@ class ElectrumGui:
tx = self.wallet.mktx([TxOutput(TYPE_ADDRESS, self.str_recipient, amount)],
password, self.config, fee)
except Exception as e:
- print(str(e))
+ print(repr(e))
return
if self.str_description:
DIR diff --git a/electrum/gui/text.py b/electrum/gui/text.py
t@@ -362,7 +362,7 @@ class ElectrumGui:
tx = self.wallet.mktx([TxOutput(TYPE_ADDRESS, self.str_recipient, amount)],
password, self.config, fee)
except Exception as e:
- self.show_message(str(e))
+ self.show_message(repr(e))
return
if self.str_description:
DIR diff --git a/electrum/jsonrpc.py b/electrum/jsonrpc.py
t@@ -68,10 +68,10 @@ class VerifyingJSONRPCServer(SimpleJSONRPCServer, Logger):
return True
except (RPCAuthCredentialsInvalid, RPCAuthCredentialsMissing,
RPCAuthUnsupportedType) as e:
- myself.send_error(401, str(e))
+ myself.send_error(401, repr(e))
except BaseException as e:
self.logger.exception('')
- myself.send_error(500, str(e))
+ myself.send_error(500, repr(e))
return False
SimpleJSONRPCServer.__init__(
DIR diff --git a/electrum/plugin.py b/electrum/plugin.py
t@@ -606,7 +606,7 @@ class DeviceMgr(ThreadJob):
new_devices = f()
except BaseException as e:
self.logger.error('custom device enum failed. func {}, error {}'
- .format(str(f), str(e)))
+ .format(str(f), repr(e)))
else:
devices.extend(new_devices)
DIR diff --git a/electrum/plugins/cosigner_pool/qt.py b/electrum/plugins/cosigner_pool/qt.py
t@@ -178,7 +178,7 @@ class Plugin(BasePlugin):
e = exc_info[1]
try: self.logger.error("on_failure", exc_info=exc_info)
except OSError: pass
- window.show_error(_("Failed to send transaction to cosigning pool") + ':\n' + str(e))
+ window.show_error(_("Failed to send transaction to cosigning pool") + ':\n' + repr(e))
for window, xpub, K, _hash in self.cosigner_list:
if not self.cosigner_can_sign(tx, xpub):
t@@ -226,7 +226,7 @@ class Plugin(BasePlugin):
message = bh2u(privkey.decrypt_message(message))
except Exception as e:
self.logger.exception('')
- window.show_error(_('Error decrypting message') + ':\n' + str(e))
+ window.show_error(_('Error decrypting message') + ':\n' + repr(e))
return
self.listener.clear(keyhash)
DIR diff --git a/electrum/plugins/email_requests/qt.py b/electrum/plugins/email_requests/qt.py
t@@ -196,7 +196,7 @@ class Plugin(BasePlugin):
self.processor.send(recipient, message, payload)
except BaseException as e:
self.logger.exception('')
- window.show_message(str(e))
+ window.show_message(repr(e))
else:
window.show_message(_('Request sent.'))
t@@ -269,4 +269,4 @@ class CheckConnectionThread(QThread):
conn = imaplib.IMAP4_SSL(self.server)
conn.login(self.username, self.password)
except BaseException as e:
- self.connection_error_signal.emit(str(e))
+ self.connection_error_signal.emit(repr(e))
DIR diff --git a/electrum/plugins/greenaddress_instant/qt.py b/electrum/plugins/greenaddress_instant/qt.py
t@@ -106,6 +106,6 @@ class Plugin(BasePlugin):
d.show_warning(_('{} is not covered by GreenAddress instant confirmation').format(tx.txid()), title=_('Verification failed!'))
except BaseException as e:
self.logger.exception('')
- d.show_error(str(e))
+ d.show_error(repr(e))
finally:
d.verify_button.setText(self.button_label)
DIR diff --git a/electrum/plugins/keepkey/keepkey.py b/electrum/plugins/keepkey/keepkey.py
t@@ -216,7 +216,7 @@ class KeepKeyPlugin(HW_PluginBase):
exit_code = 1
except BaseException as e:
self.logger.exception('')
- handler.show_error(str(e))
+ handler.show_error(repr(e))
exit_code = 1
finally:
wizard.loop.exit(exit_code)
DIR diff --git a/electrum/plugins/labels/labels.py b/electrum/plugins/labels/labels.py
t@@ -160,7 +160,7 @@ class LabelsPlugin(BasePlugin):
try:
await self.pull_thread(wallet, force)
except ErrorConnectingServer as e:
- self.logger.info(str(e))
+ self.logger.info(repr(e))
def pull(self, wallet, force):
if not wallet.network: raise Exception(_('You are offline.'))
DIR diff --git a/electrum/plugins/ledger/qt.py b/electrum/plugins/ledger/qt.py
t@@ -60,7 +60,7 @@ class Ledger_Handler(QtHandlerBase):
try:
from .auth2fa import LedgerAuthDialog
except ImportError as e:
- self.message_dialog(str(e))
+ self.message_dialog(repr(e))
return
dialog = LedgerAuthDialog(self, data)
dialog.exec_()
DIR diff --git a/electrum/plugins/safe_t/safe_t.py b/electrum/plugins/safe_t/safe_t.py
t@@ -200,7 +200,7 @@ class SafeTPlugin(HW_PluginBase):
exit_code = 1
except BaseException as e:
self.logger.exception('')
- handler.show_error(str(e))
+ handler.show_error(repr(e))
exit_code = 1
finally:
wizard.loop.exit(exit_code)
DIR diff --git a/electrum/plugins/trezor/trezor.py b/electrum/plugins/trezor/trezor.py
t@@ -222,7 +222,7 @@ class TrezorPlugin(HW_PluginBase):
exit_code = 1
except BaseException as e:
self.logger.exception('')
- handler.show_error(str(e))
+ handler.show_error(repr(e))
exit_code = 1
finally:
wizard.loop.exit(exit_code)
DIR diff --git a/electrum/plugins/trustedcoin/kivy.py b/electrum/plugins/trustedcoin/kivy.py
t@@ -74,7 +74,7 @@ class Plugin(TrustedCoinPlugin):
def accept_terms_of_use(self, wizard):
def handle_error(msg, e):
- wizard.show_error(msg + ':\n' + str(e))
+ wizard.show_error(msg + ':\n' + repr(e))
wizard.terminate()
try:
tos = server.get_terms_of_service()
DIR diff --git a/electrum/plugins/trustedcoin/qt.py b/electrum/plugins/trustedcoin/qt.py
t@@ -132,7 +132,7 @@ class Plugin(TrustedCoinPlugin):
e = exc_info[1]
window.show_error("{header}\n{exc}\n\n{tor}"
.format(header=_('Error getting TrustedCoin account info.'),
- exc=str(e),
+ exc=repr(e),
tor=_('If you keep experiencing network problems, try using a Tor proxy.')))
return WaitingDialog(parent=window,
message=_('Requesting account info from TrustedCoin server...'),
t@@ -253,7 +253,7 @@ class Plugin(TrustedCoinPlugin):
except Exception as e:
self.logger.exception('Could not retrieve Terms of Service')
tos_e.error_signal.emit(_('Could not retrieve Terms of Service:')
- + '\n' + str(e))
+ + '\n' + repr(e))
return
self.TOS = tos
tos_e.tos_signal.emit()
DIR diff --git a/electrum/plugins/trustedcoin/trustedcoin.py b/electrum/plugins/trustedcoin/trustedcoin.py
t@@ -485,7 +485,7 @@ class TrustedCoinPlugin(BasePlugin):
billing_info = server.get(wallet.get_user_id()[1])
except ErrorConnectingServer as e:
if suppress_connection_error:
- self.logger.info(str(e))
+ self.logger.info(repr(e))
return
raise
billing_index = billing_info['billing_index']
t@@ -709,7 +709,7 @@ class TrustedCoinPlugin(BasePlugin):
wizard.show_message(str(e))
wizard.terminate()
except Exception as e:
- wizard.show_message(str(e))
+ wizard.show_message(repr(e))
wizard.terminate()
else:
k3 = keystore.from_xpub(xpub3)
DIR diff --git a/electrum/synchronizer.py b/electrum/synchronizer.py
t@@ -292,6 +292,6 @@ class Notifier(SynchronizerBase):
async with session.post(url, json=data, headers=headers) as resp:
await resp.text()
except Exception as e:
- self.logger.info(str(e))
+ self.logger.info(repr(e))
else:
self.logger.info(f'Got Response for {addr}')
DIR diff --git a/electrum/verifier.py b/electrum/verifier.py
t@@ -121,7 +121,7 @@ class SPV(NetworkJobOnDefaultServer):
if self.network.config.get("skipmerklecheck"):
self.logger.info(f"skipping merkle proof check {tx_hash}")
else:
- self.logger.info(str(e))
+ self.logger.info(repr(e))
raise GracefulDisconnect(e)
# we passed all the tests
self.merkle_roots[tx_hash] = header.get('merkle_root')