From f60f690ca944b9611a6cbf7b29a8a8aab5f13b21 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Wed, 17 Jul 2019 20:12:52 +0200 Subject: [PATCH] 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) == '') --- electrum/commands.py | 2 +- electrum/dnssec.py | 2 +- electrum/gui/kivy/uix/screens.py | 4 ++-- electrum/gui/qt/__init__.py | 6 ++--- electrum/gui/qt/address_dialog.py | 2 +- electrum/gui/qt/installwizard.py | 4 ++-- electrum/gui/qt/main_window.py | 26 ++++++++++----------- electrum/gui/qt/qrtextedit.py | 4 ++-- electrum/gui/qt/transaction_dialog.py | 2 +- electrum/gui/stdio.py | 2 +- electrum/gui/text.py | 2 +- electrum/jsonrpc.py | 4 ++-- electrum/plugin.py | 2 +- electrum/plugins/cosigner_pool/qt.py | 4 ++-- electrum/plugins/email_requests/qt.py | 4 ++-- electrum/plugins/greenaddress_instant/qt.py | 2 +- electrum/plugins/keepkey/keepkey.py | 2 +- electrum/plugins/labels/labels.py | 2 +- electrum/plugins/ledger/qt.py | 2 +- electrum/plugins/safe_t/safe_t.py | 2 +- electrum/plugins/trezor/trezor.py | 2 +- electrum/plugins/trustedcoin/kivy.py | 2 +- electrum/plugins/trustedcoin/qt.py | 4 ++-- electrum/plugins/trustedcoin/trustedcoin.py | 4 ++-- electrum/synchronizer.py | 2 +- electrum/verifier.py | 2 +- 26 files changed, 48 insertions(+), 48 deletions(-) diff --git a/electrum/commands.py b/electrum/commands.py index 4defc0523..77c695c94 100644 --- a/electrum/commands.py +++ b/electrum/commands.py @@ -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): diff --git a/electrum/dnssec.py b/electrum/dnssec.py index 84b1ef43f..77671eb23 100644 --- a/electrum/dnssec.py +++ b/electrum/dnssec.py @@ -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 diff --git a/electrum/gui/kivy/uix/screens.py b/electrum/gui/kivy/uix/screens.py index 093a982fb..adb547fac 100644 --- a/electrum/gui/kivy/uix/screens.py +++ b/electrum/gui/kivy/uix/screens.py @@ -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) @@ -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') diff --git a/electrum/gui/qt/__init__.py b/electrum/gui/qt/__init__.py index 0fa9095b1..46e24ebf1 100644 --- a/electrum/gui/qt/__init__.py +++ b/electrum/gui/qt/__init__.py @@ -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 @@ -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 @@ -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)) diff --git a/electrum/gui/qt/address_dialog.py b/electrum/gui/qt/address_dialog.py index 083d51197..1e3e1af97 100644 --- a/electrum/gui/qt/address_dialog.py +++ b/electrum/gui/qt/address_dialog.py @@ -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)) diff --git a/electrum/gui/qt/installwizard.py b/electrum/gui/qt/installwizard.py index 722940042..708a79e17 100644 --- a/electrum/gui/qt/installwizard.py +++ b/electrum/gui/qt/installwizard.py @@ -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: @@ -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 diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py index 4d539a3eb..d001ba4df 100644 --- a/electrum/gui/qt/main_window.py +++ b/electrum/gui/qt/main_window.py @@ -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': @@ -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 @@ -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) @@ -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 @@ -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) @@ -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")) @@ -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): @@ -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 @@ -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) @@ -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.")) @@ -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) @@ -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 @@ -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 diff --git a/electrum/gui/qt/qrtextedit.py b/electrum/gui/qt/qrtextedit.py index a7c087937..8bae313f8 100644 --- a/electrum/gui/qt/qrtextedit.py +++ b/electrum/gui/qt/qrtextedit.py @@ -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) @@ -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 = '' diff --git a/electrum/gui/qt/transaction_dialog.py b/electrum/gui/qt/transaction_dialog.py index c3596b86d..9a5ed2fc4 100644 --- a/electrum/gui/qt/transaction_dialog.py +++ b/electrum/gui/qt/transaction_dialog.py @@ -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): diff --git a/electrum/gui/stdio.py b/electrum/gui/stdio.py index 13b640c35..7e3573661 100644 --- a/electrum/gui/stdio.py +++ b/electrum/gui/stdio.py @@ -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: diff --git a/electrum/gui/text.py b/electrum/gui/text.py index 35e8b0307..1e7d1e4b9 100644 --- a/electrum/gui/text.py +++ b/electrum/gui/text.py @@ -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: diff --git a/electrum/jsonrpc.py b/electrum/jsonrpc.py index b545e340c..dfd16cfec 100644 --- a/electrum/jsonrpc.py +++ b/electrum/jsonrpc.py @@ -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__( diff --git a/electrum/plugin.py b/electrum/plugin.py index a7313862e..f05596c38 100644 --- a/electrum/plugin.py +++ b/electrum/plugin.py @@ -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) diff --git a/electrum/plugins/cosigner_pool/qt.py b/electrum/plugins/cosigner_pool/qt.py index 531cc1700..03e5b5831 100644 --- a/electrum/plugins/cosigner_pool/qt.py +++ b/electrum/plugins/cosigner_pool/qt.py @@ -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): @@ -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) diff --git a/electrum/plugins/email_requests/qt.py b/electrum/plugins/email_requests/qt.py index 000c60d62..3926b31e3 100644 --- a/electrum/plugins/email_requests/qt.py +++ b/electrum/plugins/email_requests/qt.py @@ -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.')) @@ -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)) diff --git a/electrum/plugins/greenaddress_instant/qt.py b/electrum/plugins/greenaddress_instant/qt.py index 3e9dc79a7..2006c1462 100644 --- a/electrum/plugins/greenaddress_instant/qt.py +++ b/electrum/plugins/greenaddress_instant/qt.py @@ -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) diff --git a/electrum/plugins/keepkey/keepkey.py b/electrum/plugins/keepkey/keepkey.py index 93cf709b2..549de1558 100644 --- a/electrum/plugins/keepkey/keepkey.py +++ b/electrum/plugins/keepkey/keepkey.py @@ -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) diff --git a/electrum/plugins/labels/labels.py b/electrum/plugins/labels/labels.py index 9118a9f89..c63ed92b2 100644 --- a/electrum/plugins/labels/labels.py +++ b/electrum/plugins/labels/labels.py @@ -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.')) diff --git a/electrum/plugins/ledger/qt.py b/electrum/plugins/ledger/qt.py index 225c5ef4f..e10aa50d6 100644 --- a/electrum/plugins/ledger/qt.py +++ b/electrum/plugins/ledger/qt.py @@ -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_() diff --git a/electrum/plugins/safe_t/safe_t.py b/electrum/plugins/safe_t/safe_t.py index 379243d7b..c03885019 100644 --- a/electrum/plugins/safe_t/safe_t.py +++ b/electrum/plugins/safe_t/safe_t.py @@ -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) diff --git a/electrum/plugins/trezor/trezor.py b/electrum/plugins/trezor/trezor.py index 75b168f26..ecf3ebf22 100644 --- a/electrum/plugins/trezor/trezor.py +++ b/electrum/plugins/trezor/trezor.py @@ -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) diff --git a/electrum/plugins/trustedcoin/kivy.py b/electrum/plugins/trustedcoin/kivy.py index 4cd01fbe8..12eb7c0fa 100644 --- a/electrum/plugins/trustedcoin/kivy.py +++ b/electrum/plugins/trustedcoin/kivy.py @@ -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() diff --git a/electrum/plugins/trustedcoin/qt.py b/electrum/plugins/trustedcoin/qt.py index b11de233e..389dead49 100644 --- a/electrum/plugins/trustedcoin/qt.py +++ b/electrum/plugins/trustedcoin/qt.py @@ -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...'), @@ -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() diff --git a/electrum/plugins/trustedcoin/trustedcoin.py b/electrum/plugins/trustedcoin/trustedcoin.py index ed9ef6d18..809893999 100644 --- a/electrum/plugins/trustedcoin/trustedcoin.py +++ b/electrum/plugins/trustedcoin/trustedcoin.py @@ -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'] @@ -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) diff --git a/electrum/synchronizer.py b/electrum/synchronizer.py index 313467a8d..fa2967b15 100644 --- a/electrum/synchronizer.py +++ b/electrum/synchronizer.py @@ -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}') diff --git a/electrum/verifier.py b/electrum/verifier.py index d73dcb96d..e6b8ecf35 100644 --- a/electrum/verifier.py +++ b/electrum/verifier.py @@ -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')