don't use bare except
use "except Exception", or if really needed explicitly "except BaseException"
This commit is contained in:
@@ -130,7 +130,7 @@ class BaseCrashReporter(Logger):
|
||||
}
|
||||
try:
|
||||
args["wallet_type"] = self.get_wallet_type()
|
||||
except:
|
||||
except Exception:
|
||||
# Maybe the wallet isn't loaded yet
|
||||
pass
|
||||
return args
|
||||
|
||||
@@ -351,7 +351,7 @@ class BaseWizard(Logger):
|
||||
state = _("initialized") if info.initialized else _("wiped")
|
||||
label = info.label or _("An unnamed {}").format(name)
|
||||
try: transport_str = info.device.transport_ui_string[:20]
|
||||
except: transport_str = 'unknown transport'
|
||||
except Exception: transport_str = 'unknown transport'
|
||||
descr = f"{label} [{info.model_name or name}, {state}, {transport_str}]"
|
||||
choices.append(((name, info), descr))
|
||||
msg = _('Select a device') + ':'
|
||||
|
||||
+3
-3
@@ -297,7 +297,7 @@ def is_xpub(text):
|
||||
try:
|
||||
node = BIP32Node.from_xkey(text)
|
||||
return not node.is_private()
|
||||
except:
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
@@ -305,7 +305,7 @@ def is_xprv(text):
|
||||
try:
|
||||
node = BIP32Node.from_xkey(text)
|
||||
return node.is_private()
|
||||
except:
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
@@ -374,7 +374,7 @@ def is_bip32_derivation(s: str) -> bool:
|
||||
if not (s == 'm' or s.startswith('m/')):
|
||||
return False
|
||||
convert_bip32_strpath_to_intpath(s)
|
||||
except:
|
||||
except Exception:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
@@ -622,7 +622,7 @@ class Blockchain(Logger):
|
||||
return hash_header(header) == constants.net.GENESIS
|
||||
try:
|
||||
prev_hash = self.get_hash(height - 1)
|
||||
except:
|
||||
except Exception:
|
||||
return False
|
||||
if prev_hash != header.get('prev_block_hash'):
|
||||
return False
|
||||
|
||||
@@ -175,7 +175,7 @@ class NodeInfo(NamedTuple):
|
||||
alias = payload['alias'].rstrip(b'\x00')
|
||||
try:
|
||||
alias = alias.decode('utf8')
|
||||
except:
|
||||
except Exception:
|
||||
alias = ''
|
||||
timestamp = payload['timestamp']
|
||||
node_info = NodeInfo(node_id=node_id, features=features, timestamp=timestamp, alias=alias)
|
||||
|
||||
@@ -313,7 +313,7 @@ class Commands:
|
||||
# call literal_eval for backward compatibility (see #4225)
|
||||
try:
|
||||
value = ast.literal_eval(value)
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
return value
|
||||
|
||||
@@ -631,7 +631,7 @@ class Commands:
|
||||
"""Convert xtype of a master key. e.g. xpub -> ypub"""
|
||||
try:
|
||||
node = BIP32Node.from_xkey(xkey)
|
||||
except:
|
||||
except Exception:
|
||||
raise Exception('xkey should be a master public/private key')
|
||||
return node._replace(xtype=xtype).to_xkey()
|
||||
|
||||
@@ -1376,7 +1376,7 @@ def eval_bool(x: str) -> bool:
|
||||
if x == 'true': return True
|
||||
try:
|
||||
return bool(ast.literal_eval(x))
|
||||
except:
|
||||
except Exception:
|
||||
return bool(x)
|
||||
|
||||
param_descriptions = {
|
||||
|
||||
@@ -35,7 +35,7 @@ def read_json(filename, default):
|
||||
try:
|
||||
with open(path, 'r') as f:
|
||||
r = json.loads(f.read())
|
||||
except:
|
||||
except Exception:
|
||||
r = default
|
||||
return r
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ class Contacts(dict, Logger):
|
||||
d = self.db.get('contacts', {})
|
||||
try:
|
||||
self.update(d)
|
||||
except:
|
||||
except Exception:
|
||||
return
|
||||
# backward compatibility
|
||||
for k, v in self.items():
|
||||
|
||||
+3
-3
@@ -42,7 +42,7 @@ _logger = get_logger(__name__)
|
||||
HAS_PYAES = False
|
||||
try:
|
||||
import pyaes
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
HAS_PYAES = True
|
||||
@@ -57,7 +57,7 @@ try:
|
||||
from Cryptodome.Cipher import ChaCha20_Poly1305 as CD_ChaCha20_Poly1305
|
||||
from Cryptodome.Cipher import ChaCha20 as CD_ChaCha20
|
||||
from Cryptodome.Cipher import AES as CD_AES
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
HAS_CRYPTODOME = True
|
||||
@@ -75,7 +75,7 @@ try:
|
||||
from cryptography.hazmat.primitives.ciphers import modes as CG_modes
|
||||
from cryptography.hazmat.backends import default_backend as CG_default_backend
|
||||
import cryptography.hazmat.primitives.ciphers.aead as CG_aead
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
HAS_CRYPTOGRAPHY = True
|
||||
|
||||
+1
-1
@@ -370,7 +370,7 @@ class ECPubkey(object):
|
||||
try:
|
||||
ECPubkey(b)
|
||||
return True
|
||||
except:
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
|
||||
@@ -104,7 +104,7 @@ class ExchangeBase(Logger):
|
||||
try:
|
||||
with open(filename, 'r', encoding='utf-8') as f:
|
||||
h = json.loads(f.read())
|
||||
except:
|
||||
except Exception:
|
||||
return None
|
||||
if not h: # e.g. empty dict
|
||||
return None
|
||||
@@ -469,7 +469,7 @@ def get_exchanges_and_currencies():
|
||||
try:
|
||||
with open(path, 'r', encoding='utf-8') as f:
|
||||
return json.loads(f.read())
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
# or if not present, generate it now.
|
||||
print("cannot find currencies.json. will regenerate it now.")
|
||||
@@ -483,7 +483,7 @@ def get_exchanges_and_currencies():
|
||||
try:
|
||||
d[name] = await exchange.get_currencies()
|
||||
print(name, "ok")
|
||||
except:
|
||||
except Exception:
|
||||
print(name, "error")
|
||||
|
||||
async def query_all_exchanges_for_their_ccys_over_network():
|
||||
|
||||
@@ -22,14 +22,14 @@ class _(str):
|
||||
def bind(label):
|
||||
try:
|
||||
_.observers.add(label)
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
# garbage collection
|
||||
new = set()
|
||||
for label in _.observers:
|
||||
try:
|
||||
new.add(label)
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
_.observers = new
|
||||
|
||||
@@ -42,7 +42,7 @@ class _(str):
|
||||
for label in _.observers:
|
||||
try:
|
||||
label.text = _(label.text.source_text)
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
# Note that all invocations of _() inside the core electrum library
|
||||
# use electrum.i18n instead of electrum.gui.kivy.i18n, so we should update the
|
||||
|
||||
@@ -358,7 +358,7 @@ class ElectrumWindow(App, Logger, EventListener):
|
||||
assert u == self.base_unit
|
||||
try:
|
||||
x = Decimal(a)
|
||||
except:
|
||||
except Exception:
|
||||
return None
|
||||
p = pow(10, self.decimal_point())
|
||||
return int(p * x)
|
||||
@@ -487,7 +487,7 @@ class ElectrumWindow(App, Logger, EventListener):
|
||||
from electrum.transaction import tx_from_any
|
||||
try:
|
||||
tx = tx_from_any(data)
|
||||
except:
|
||||
except Exception:
|
||||
tx = None
|
||||
if tx:
|
||||
self.tx_dialog(tx)
|
||||
|
||||
@@ -145,7 +145,7 @@ class AmountDialog(Factory.Popup):
|
||||
try:
|
||||
Decimal(amount+c)
|
||||
amount += c
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
# truncate btc amounts to max precision:
|
||||
if not kb.is_fiat and '.' in amount:
|
||||
|
||||
@@ -665,7 +665,7 @@ class WizardOTPDialogBase(WizardDialog):
|
||||
return
|
||||
try:
|
||||
return int(otp)
|
||||
except:
|
||||
except Exception:
|
||||
return
|
||||
|
||||
def on_text(self, dt):
|
||||
@@ -1037,7 +1037,7 @@ class AddXpubDialog(WizardDialog):
|
||||
def is_valid(x):
|
||||
try:
|
||||
return kwargs['is_valid'](x)
|
||||
except:
|
||||
except Exception:
|
||||
return False
|
||||
self.is_valid = is_valid
|
||||
self.title = kwargs['title']
|
||||
|
||||
@@ -341,7 +341,7 @@ class SendScreen(CScreen, Logger):
|
||||
else:
|
||||
try:
|
||||
amount_sat = self.app.get_amount(self.amount)
|
||||
except:
|
||||
except Exception:
|
||||
self.app.show_error(_('Invalid amount') + ':\n' + self.amount)
|
||||
return
|
||||
message = self.message
|
||||
@@ -384,7 +384,7 @@ class SendScreen(CScreen, Logger):
|
||||
assert self.lnurl_data
|
||||
try:
|
||||
amount = self.app.get_amount(self.amount)
|
||||
except:
|
||||
except Exception:
|
||||
self.app.show_error(_('Invalid amount') + ':\n' + self.amount)
|
||||
return
|
||||
if not (self.lnurl_data.min_sendable_sat <= amount <= self.lnurl_data.max_sendable_sat):
|
||||
|
||||
@@ -108,7 +108,7 @@ class QEAppController(BaseCrashReporter, QObject):
|
||||
# connect only once
|
||||
try:
|
||||
qewallet.userNotify.disconnect(self.on_wallet_usernotify)
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
qewallet.userNotify.connect(self.on_wallet_usernotify)
|
||||
|
||||
|
||||
@@ -158,7 +158,7 @@ class QEBitcoin(QObject):
|
||||
try:
|
||||
tx_from_any(rawtx)
|
||||
return True
|
||||
except:
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
@pyqtSlot(str, result=bool)
|
||||
|
||||
@@ -248,7 +248,7 @@ class QEConfig(AuthMixin, QObject):
|
||||
self._amount = QEAmount()
|
||||
try:
|
||||
x = Decimal(unitAmount)
|
||||
except:
|
||||
except Exception:
|
||||
return self._amount
|
||||
|
||||
# scale it to max allowed precision, make it an int
|
||||
|
||||
@@ -105,7 +105,7 @@ class QEFX(QObject, QtEventListener):
|
||||
else:
|
||||
try:
|
||||
sd = Decimal(satoshis)
|
||||
except:
|
||||
except Exception:
|
||||
return ''
|
||||
if plain:
|
||||
return self.fx.ccy_amount_str(self.fx.fiat_value(satoshis, rate), add_thousands_sep=False)
|
||||
@@ -122,14 +122,14 @@ class QEFX(QObject, QtEventListener):
|
||||
else:
|
||||
try:
|
||||
sd = Decimal(satoshis)
|
||||
except:
|
||||
except Exception:
|
||||
return ''
|
||||
|
||||
try:
|
||||
td = Decimal(timestamp)
|
||||
if td == 0:
|
||||
return ''
|
||||
except:
|
||||
except Exception:
|
||||
return ''
|
||||
dt = datetime.fromtimestamp(int(td))
|
||||
if plain:
|
||||
@@ -143,7 +143,7 @@ class QEFX(QObject, QtEventListener):
|
||||
rate = self.fx.exchange_rate()
|
||||
try:
|
||||
fd = Decimal(fiat)
|
||||
except:
|
||||
except Exception:
|
||||
return ''
|
||||
v = fd / Decimal(rate) * COIN
|
||||
if v.is_nan():
|
||||
|
||||
@@ -617,7 +617,7 @@ class QEInvoiceParser(QEInvoice):
|
||||
try:
|
||||
assert amount >= self.lnurlData['min_sendable_sat']
|
||||
assert amount <= self.lnurlData['max_sendable_sat']
|
||||
except:
|
||||
except Exception:
|
||||
self.lnurlError.emit('amount', _('Amount out of bounds'))
|
||||
return
|
||||
|
||||
|
||||
@@ -323,7 +323,7 @@ class QETxDetails(QObject, QtEventListener):
|
||||
if broadcast:
|
||||
self._wallet.broadcastSucceeded.disconnect(self.onBroadcastSucceeded)
|
||||
self._wallet.broadcastfailed.disconnect(self.onBroadcastFailed)
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if broadcast:
|
||||
@@ -344,7 +344,7 @@ class QETxDetails(QObject, QtEventListener):
|
||||
|
||||
try:
|
||||
self._wallet.broadcastfailed.disconnect(self.onBroadcastFailed)
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
self._wallet.broadcastFailed.connect(self.onBroadcastFailed)
|
||||
|
||||
|
||||
@@ -739,7 +739,7 @@ class QEWallet(AuthMixin, QObject, QtEventListener):
|
||||
try:
|
||||
self._seed = self.wallet.get_seed(self.password)
|
||||
self.seedRetrieved.emit()
|
||||
except:
|
||||
except Exception:
|
||||
self._seed = ''
|
||||
|
||||
self.dataChanged.emit()
|
||||
|
||||
@@ -97,7 +97,7 @@ class AmountEdit(SizedFreezableLineEdit):
|
||||
try:
|
||||
text = text.replace(DECIMAL_POINT, '.')
|
||||
return (int if self.is_int else Decimal)(text)
|
||||
except:
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
def get_amount(self) -> Union[None, Decimal, int]:
|
||||
@@ -130,7 +130,7 @@ class BTCAmountEdit(AmountEdit):
|
||||
try:
|
||||
text = text.replace(DECIMAL_POINT, '.')
|
||||
x = Decimal(text)
|
||||
except:
|
||||
except Exception:
|
||||
return None
|
||||
# scale it to max allowed precision, make it an int
|
||||
power = pow(10, self.max_precision())
|
||||
|
||||
@@ -92,7 +92,7 @@ class HistorySortModel(QSortFilterProxyModel):
|
||||
if v2 is None or isinstance(v2, Decimal) and v2.is_nan(): v2 = -float("inf")
|
||||
try:
|
||||
return v1 < v2
|
||||
except:
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
def get_item_key(tx_item):
|
||||
@@ -538,7 +538,7 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
|
||||
else:
|
||||
try:
|
||||
year = int(s)
|
||||
except:
|
||||
except Exception:
|
||||
return
|
||||
self.start_date = datetime.datetime(year, 1, 1)
|
||||
self.end_date = datetime.datetime(year+1, 1, 1)
|
||||
|
||||
@@ -93,7 +93,7 @@ class _LockTimeEditor:
|
||||
return True
|
||||
try:
|
||||
x = int(x)
|
||||
except:
|
||||
except Exception:
|
||||
return False
|
||||
return cls.min_allowed_value <= x <= cls.max_allowed_value
|
||||
|
||||
@@ -120,13 +120,13 @@ class LockTimeRawEdit(QLineEdit, _LockTimeEditor):
|
||||
def get_locktime(self) -> Optional[int]:
|
||||
try:
|
||||
return int(str(self.text()))
|
||||
except:
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
def set_locktime(self, x: Any) -> None:
|
||||
try:
|
||||
x = int(x)
|
||||
except:
|
||||
except Exception:
|
||||
self.setText('')
|
||||
return
|
||||
x = max(x, self.min_allowed_value)
|
||||
@@ -185,7 +185,7 @@ class LockTimeDateEdit(QDateTimeEdit, _LockTimeEditor):
|
||||
return
|
||||
try:
|
||||
x = int(x)
|
||||
except:
|
||||
except Exception:
|
||||
self.setDateTime(QDateTime.currentDateTime())
|
||||
return
|
||||
dt = datetime.fromtimestamp(x)
|
||||
|
||||
@@ -515,7 +515,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener):
|
||||
screen = self.app.desktop().screenGeometry()
|
||||
assert screen.contains(QRect(*winpos))
|
||||
self.setGeometry(*winpos)
|
||||
except:
|
||||
except Exception:
|
||||
self.logger.info("using default geometry")
|
||||
self.setGeometry(100, 100, 840, 400)
|
||||
|
||||
@@ -631,7 +631,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener):
|
||||
recent = self.config.get('recently_open', [])
|
||||
try:
|
||||
sorted(recent)
|
||||
except:
|
||||
except Exception:
|
||||
recent = []
|
||||
if filename in recent:
|
||||
recent.remove(filename)
|
||||
|
||||
@@ -125,7 +125,7 @@ class MySortModel(QSortFilterProxyModel):
|
||||
v2 = item2.text()
|
||||
try:
|
||||
return Decimal(v1) < Decimal(v2)
|
||||
except:
|
||||
except Exception:
|
||||
return v1 < v2
|
||||
|
||||
class ElectrumItemDelegate(QStyledItemDelegate):
|
||||
|
||||
@@ -287,7 +287,7 @@ class SettingsDialog(QDialog, QtEventListener):
|
||||
val = block_ex_custom_e.text()
|
||||
try:
|
||||
val = ast.literal_eval(val) # to also accept tuples
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
self.config.set_key('block_explorer_custom', val)
|
||||
block_ex_custom_e.editingFinished.connect(on_be_edit)
|
||||
|
||||
@@ -727,7 +727,7 @@ class OverlayControlMixin(GenericInputHandler):
|
||||
from .qrcodewidget import QRDialog
|
||||
try:
|
||||
s = str(self.text())
|
||||
except:
|
||||
except Exception:
|
||||
s = self.text()
|
||||
if not s:
|
||||
return
|
||||
|
||||
@@ -35,14 +35,14 @@ _ = lambda x:x # i18n
|
||||
def parse_bip21(text):
|
||||
try:
|
||||
return util.parse_URI(text)
|
||||
except:
|
||||
except Exception:
|
||||
return
|
||||
|
||||
def parse_bolt11(text):
|
||||
from electrum.lnaddr import lndecode
|
||||
try:
|
||||
return lndecode(text)
|
||||
except:
|
||||
except Exception:
|
||||
return
|
||||
|
||||
|
||||
@@ -594,7 +594,7 @@ class ElectrumGui(BaseElectrumGui, EventListener):
|
||||
def parse_amount(self, text):
|
||||
try:
|
||||
x = Decimal(text)
|
||||
except:
|
||||
except Exception:
|
||||
return None
|
||||
power = pow(10, self.config.get_decimal_point())
|
||||
return int(power * x)
|
||||
|
||||
@@ -1153,14 +1153,14 @@ def check_cert(host, cert):
|
||||
try:
|
||||
b = pem.dePem(cert, 'CERTIFICATE')
|
||||
x = x509.X509(b)
|
||||
except:
|
||||
except Exception:
|
||||
traceback.print_exc(file=sys.stdout)
|
||||
return
|
||||
|
||||
try:
|
||||
x.check_date()
|
||||
expired = False
|
||||
except:
|
||||
except Exception:
|
||||
expired = True
|
||||
|
||||
m = "host: %s\n"%host
|
||||
|
||||
+1
-1
@@ -155,7 +155,7 @@ class JsonDB(Logger):
|
||||
try:
|
||||
json.dumps(key, cls=JsonDBJsonEncoder)
|
||||
json.dumps(value, cls=JsonDBJsonEncoder)
|
||||
except:
|
||||
except Exception:
|
||||
self.logger.info(f"json error: cannot save {repr(key)} ({repr(value)})")
|
||||
return False
|
||||
if value is not None:
|
||||
|
||||
@@ -1084,13 +1084,13 @@ def load_keystore(db: 'WalletDB', name: str) -> KeyStore:
|
||||
def is_old_mpk(mpk: str) -> bool:
|
||||
try:
|
||||
int(mpk, 16) # test if hex string
|
||||
except:
|
||||
except Exception:
|
||||
return False
|
||||
if len(mpk) != 128:
|
||||
return False
|
||||
try:
|
||||
ecc.ECPubkey(bfh('04' + mpk))
|
||||
except:
|
||||
except Exception:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
+8
-8
@@ -602,7 +602,7 @@ class Peer(Logger):
|
||||
try:
|
||||
if self.transport:
|
||||
self.transport.close()
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
self.lnworker.peer_closed(self)
|
||||
self.got_disconnected.set()
|
||||
@@ -1594,7 +1594,7 @@ class Peer(Logger):
|
||||
raise OnionRoutingFailure(code=OnionFailureCode.TEMPORARY_NODE_FAILURE, data=b'')
|
||||
try:
|
||||
next_chan_scid = processed_onion.hop_data.payload["short_channel_id"]["short_channel_id"]
|
||||
except:
|
||||
except Exception:
|
||||
raise OnionRoutingFailure(code=OnionFailureCode.INVALID_ONION_PAYLOAD, data=b'\x00\x00\x00')
|
||||
next_chan = self.lnworker.get_channel_by_short_id(next_chan_scid)
|
||||
local_height = chain.height()
|
||||
@@ -1610,14 +1610,14 @@ class Peer(Logger):
|
||||
raise OnionRoutingFailure(code=OnionFailureCode.TEMPORARY_CHANNEL_FAILURE, data=outgoing_chan_upd_message)
|
||||
try:
|
||||
next_amount_msat_htlc = processed_onion.hop_data.payload["amt_to_forward"]["amt_to_forward"]
|
||||
except:
|
||||
except Exception:
|
||||
raise OnionRoutingFailure(code=OnionFailureCode.INVALID_ONION_PAYLOAD, data=b'\x00\x00\x00')
|
||||
if not next_chan.can_pay(next_amount_msat_htlc):
|
||||
self.logger.info(f"cannot forward htlc due to transient errors (likely due to insufficient funds)")
|
||||
raise OnionRoutingFailure(code=OnionFailureCode.TEMPORARY_CHANNEL_FAILURE, data=outgoing_chan_upd_message)
|
||||
try:
|
||||
next_cltv_expiry = processed_onion.hop_data.payload["outgoing_cltv_value"]["outgoing_cltv_value"]
|
||||
except:
|
||||
except Exception:
|
||||
raise OnionRoutingFailure(code=OnionFailureCode.INVALID_ONION_PAYLOAD, data=b'\x00\x00\x00')
|
||||
if htlc.cltv_expiry - next_cltv_expiry < next_chan.forwarding_cltv_expiry_delta:
|
||||
data = htlc.cltv_expiry.to_bytes(4, byteorder="big") + outgoing_chan_upd_message
|
||||
@@ -1746,7 +1746,7 @@ class Peer(Logger):
|
||||
|
||||
try:
|
||||
amt_to_forward = processed_onion.hop_data.payload["amt_to_forward"]["amt_to_forward"]
|
||||
except:
|
||||
except Exception:
|
||||
log_fail_reason(f"'amt_to_forward' missing from onion")
|
||||
raise OnionRoutingFailure(code=OnionFailureCode.INVALID_ONION_PAYLOAD, data=b'\x00\x00\x00')
|
||||
|
||||
@@ -1766,7 +1766,7 @@ class Peer(Logger):
|
||||
raise exc_incorrect_or_unknown_pd
|
||||
try:
|
||||
cltv_from_onion = processed_onion.hop_data.payload["outgoing_cltv_value"]["outgoing_cltv_value"]
|
||||
except:
|
||||
except Exception:
|
||||
log_fail_reason(f"'outgoing_cltv_value' missing from onion")
|
||||
raise OnionRoutingFailure(code=OnionFailureCode.INVALID_ONION_PAYLOAD, data=b'\x00\x00\x00')
|
||||
|
||||
@@ -1778,7 +1778,7 @@ class Peer(Logger):
|
||||
data=htlc.cltv_expiry.to_bytes(4, byteorder="big"))
|
||||
try:
|
||||
total_msat = processed_onion.hop_data.payload["payment_data"]["total_msat"]
|
||||
except:
|
||||
except Exception:
|
||||
total_msat = amt_to_forward # fall back to "amt_to_forward"
|
||||
|
||||
if not is_trampoline and amt_to_forward != htlc.amount_msat:
|
||||
@@ -1789,7 +1789,7 @@ class Peer(Logger):
|
||||
|
||||
try:
|
||||
payment_secret_from_onion = processed_onion.hop_data.payload["payment_data"]["payment_secret"]
|
||||
except:
|
||||
except Exception:
|
||||
if total_msat > amt_to_forward:
|
||||
# payment_secret is required for MPP
|
||||
log_fail_reason(f"'payment_secret' missing from onion")
|
||||
|
||||
+2
-2
@@ -1470,7 +1470,7 @@ def extract_nodeid(connect_contents: str) -> Tuple[bytes, Optional[str]]:
|
||||
invoice = lndecode(connect_contents)
|
||||
nodeid_bytes = invoice.pubkey.serialize()
|
||||
nodeid_hex = nodeid_bytes.hex()
|
||||
except:
|
||||
except Exception:
|
||||
# node id as hex?
|
||||
nodeid_hex = connect_contents
|
||||
if rest == '':
|
||||
@@ -1479,7 +1479,7 @@ def extract_nodeid(connect_contents: str) -> Tuple[bytes, Optional[str]]:
|
||||
node_id = bfh(nodeid_hex)
|
||||
if len(node_id) != 33:
|
||||
raise Exception()
|
||||
except:
|
||||
except Exception:
|
||||
raise ConnStringFormatError(_('Invalid node ID, must be 33 bytes and hexadecimal'))
|
||||
return node_id, rest
|
||||
|
||||
|
||||
@@ -1072,7 +1072,7 @@ class LNWallet(LNWorker):
|
||||
self.wallet.set_reserved_state_of_address(addr, reserved=True)
|
||||
try:
|
||||
self.save_channel(chan)
|
||||
except:
|
||||
except Exception:
|
||||
chan.set_state(ChannelState.REDEEMED)
|
||||
self.remove_channel(chan.channel_id)
|
||||
raise
|
||||
@@ -1516,13 +1516,13 @@ class LNWallet(LNWorker):
|
||||
if payload['chain_hash'] != constants.net.rev_genesis_bytes(): raise Exception()
|
||||
payload['raw'] = channel_update_typed
|
||||
return payload
|
||||
except: # FIXME: too broad
|
||||
except Exception: # FIXME: too broad
|
||||
try:
|
||||
message_type, payload = decode_msg(channel_update_as_received)
|
||||
if payload['chain_hash'] != constants.net.rev_genesis_bytes(): raise Exception()
|
||||
payload['raw'] = channel_update_as_received
|
||||
return payload
|
||||
except:
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
|
||||
+5
-5
@@ -403,7 +403,7 @@ class Network(Logger, NetworkRetryManager[ServerAddr]):
|
||||
data = f.read()
|
||||
servers_list = json.loads(data)
|
||||
return [ServerAddr.from_str(s) for s in servers_list]
|
||||
except:
|
||||
except Exception:
|
||||
return []
|
||||
|
||||
@with_recent_servers_lock
|
||||
@@ -415,7 +415,7 @@ class Network(Logger, NetworkRetryManager[ServerAddr]):
|
||||
try:
|
||||
with open(path, "w", encoding='utf-8') as f:
|
||||
f.write(s)
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
async def _server_is_lagging(self) -> bool:
|
||||
@@ -516,7 +516,7 @@ class Network(Logger, NetworkRetryManager[ServerAddr]):
|
||||
for n in FEE_ETA_TARGETS:
|
||||
try:
|
||||
out[n] = int(median(filter(None, [i.fee_estimates_eta.get(n) for i in self.interfaces.values()])))
|
||||
except:
|
||||
except Exception:
|
||||
continue
|
||||
return out
|
||||
else:
|
||||
@@ -595,7 +595,7 @@ class Network(Logger, NetworkRetryManager[ServerAddr]):
|
||||
if server:
|
||||
try:
|
||||
self.default_server = ServerAddr.from_str(server)
|
||||
except:
|
||||
except Exception:
|
||||
self.logger.warning(f'failed to parse server-string ({server!r}); falling back to localhost:1:s.')
|
||||
self.default_server = ServerAddr.from_str("localhost:1:s")
|
||||
else:
|
||||
@@ -626,7 +626,7 @@ class Network(Logger, NetworkRetryManager[ServerAddr]):
|
||||
if proxy:
|
||||
proxy_modes.index(proxy['mode']) + 1
|
||||
int(proxy['port'])
|
||||
except:
|
||||
except Exception:
|
||||
return
|
||||
self.config.set_key('auto_connect', net_params.auto_connect, False)
|
||||
self.config.set_key('oneserver', net_params.oneserver, False)
|
||||
|
||||
@@ -126,7 +126,7 @@ class PaymentRequest:
|
||||
try:
|
||||
self.data = pb2.PaymentRequest()
|
||||
self.data.ParseFromString(r)
|
||||
except:
|
||||
except Exception:
|
||||
self.error = "cannot parse payment request"
|
||||
return
|
||||
self.details = pb2.PaymentDetails()
|
||||
@@ -157,7 +157,7 @@ class PaymentRequest:
|
||||
pr = pb2.PaymentRequest()
|
||||
try:
|
||||
pr.ParseFromString(self.raw)
|
||||
except:
|
||||
except Exception:
|
||||
self.error = "Error: Cannot parse payment request"
|
||||
return False
|
||||
if not pr.signature:
|
||||
|
||||
@@ -79,7 +79,7 @@ class BitBox02Client(HardwareClientBase):
|
||||
def close(self):
|
||||
try:
|
||||
self.bitbox02_device.close()
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def has_usable_connection_with_device(self) -> bool:
|
||||
@@ -104,7 +104,7 @@ class BitBox02Client(HardwareClientBase):
|
||||
self.handler.show_message(msg)
|
||||
try:
|
||||
res = device_response()
|
||||
except:
|
||||
except Exception:
|
||||
# Close the hid device on exception
|
||||
hid_device.close()
|
||||
raise
|
||||
@@ -327,7 +327,7 @@ class BitBox02Client(HardwareClientBase):
|
||||
)
|
||||
except bitbox02.DuplicateEntryException:
|
||||
raise
|
||||
except:
|
||||
except Exception:
|
||||
raise UserFacingException("Failed to register multisig\naccount configuration on BitBox02")
|
||||
return multisig_config
|
||||
|
||||
@@ -648,7 +648,7 @@ class BitBox02Plugin(HW_PluginBase):
|
||||
try:
|
||||
from bitbox02 import bitbox02
|
||||
version = bitbox02.__version__
|
||||
except:
|
||||
except Exception:
|
||||
version = "unknown"
|
||||
if requirements_ok:
|
||||
return version
|
||||
|
||||
@@ -160,7 +160,7 @@ class CKCCClient(HardwareClientBase):
|
||||
try:
|
||||
self.ping_check()
|
||||
return True
|
||||
except:
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
@runs_in_hwd_thread
|
||||
@@ -187,7 +187,7 @@ class CKCCClient(HardwareClientBase):
|
||||
try:
|
||||
echo = self.dev.send_recv(CCProtocolPacker.ping(req))
|
||||
assert echo == req
|
||||
except:
|
||||
except Exception:
|
||||
raise RuntimeError("Communication trouble with Coldcard")
|
||||
|
||||
@runs_in_hwd_thread
|
||||
|
||||
@@ -81,7 +81,7 @@ class DigitalBitbox_Client(HardwareClientBase):
|
||||
if self.opened:
|
||||
try:
|
||||
self.dbb_hid.close()
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
self.opened = False
|
||||
|
||||
|
||||
@@ -411,7 +411,7 @@ class JadePlugin(HW_PluginBase):
|
||||
version = jadepy.__version__
|
||||
except ImportError:
|
||||
raise
|
||||
except:
|
||||
except Exception:
|
||||
version = "unknown"
|
||||
return version
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ class LabelsPlugin(BasePlugin):
|
||||
try:
|
||||
encoded_key = self.encode(wallet, key)
|
||||
encoded_value = self.encode(wallet, value)
|
||||
except:
|
||||
except Exception:
|
||||
self.logger.info(f'cannot encode {repr(key)} {repr(value)}')
|
||||
continue
|
||||
bundle["labels"].append({'encryptedLabel': encoded_value,
|
||||
@@ -142,12 +142,12 @@ class LabelsPlugin(BasePlugin):
|
||||
try:
|
||||
key = self.decode(wallet, label["externalId"])
|
||||
value = self.decode(wallet, label["encryptedLabel"])
|
||||
except:
|
||||
except Exception:
|
||||
continue
|
||||
try:
|
||||
json.dumps(key)
|
||||
json.dumps(value)
|
||||
except:
|
||||
except Exception:
|
||||
self.logger.info(f'error: no json {key}')
|
||||
continue
|
||||
if value:
|
||||
|
||||
@@ -1355,7 +1355,7 @@ class LedgerPlugin(HW_PluginBase):
|
||||
version = ledger_bitcoin.__version__
|
||||
except ImportError:
|
||||
raise
|
||||
except:
|
||||
except Exception:
|
||||
version = "unknown"
|
||||
if LEDGER_BITCOIN:
|
||||
return version
|
||||
|
||||
@@ -47,7 +47,7 @@ class RevealerPlugin(BasePlugin):
|
||||
return None
|
||||
try:
|
||||
int(txt, 16)
|
||||
except:
|
||||
except Exception:
|
||||
return None
|
||||
version = txt[0]
|
||||
if version not in cls.KNOWN_VERSIONS:
|
||||
|
||||
@@ -133,12 +133,12 @@ class TrustedCoinCosignerClient(Logger):
|
||||
try:
|
||||
r = await resp.json()
|
||||
message = r['message']
|
||||
except:
|
||||
except Exception:
|
||||
message = await resp.text()
|
||||
raise TrustedCoinException(message, resp.status)
|
||||
try:
|
||||
return await resp.json()
|
||||
except:
|
||||
except Exception:
|
||||
return await resp.text()
|
||||
|
||||
def send_request(self, method, relative_url, data=None, *, timeout=None):
|
||||
|
||||
@@ -12,7 +12,7 @@ from electrum.simple_config import SimpleConfig
|
||||
|
||||
try:
|
||||
rawtx = sys.argv[1]
|
||||
except:
|
||||
except Exception:
|
||||
print("usage: txbroadcast rawtx")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ from electrum.simple_config import SimpleConfig
|
||||
|
||||
try:
|
||||
txid = sys.argv[1]
|
||||
except:
|
||||
except Exception:
|
||||
print("usage: txradar txid")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
@@ -165,7 +165,7 @@ class SimpleConfig(Logger):
|
||||
try:
|
||||
json.dumps(key)
|
||||
json.dumps(value)
|
||||
except:
|
||||
except Exception:
|
||||
self.logger.info(f"json error: cannot save {repr(key)} ({repr(value)})")
|
||||
return
|
||||
self._set_key_in_user_config(key, value, save)
|
||||
@@ -674,7 +674,7 @@ class SimpleConfig(Logger):
|
||||
if text:
|
||||
try:
|
||||
return NetAddress.from_string(text)
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def format_amount(
|
||||
|
||||
+1
-1
@@ -142,7 +142,7 @@ class WalletStorage(Logger):
|
||||
return StorageEncryptionVersion.XPUB_PASSWORD
|
||||
else:
|
||||
return StorageEncryptionVersion.PLAINTEXT
|
||||
except:
|
||||
except Exception:
|
||||
return StorageEncryptionVersion.PLAINTEXT
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -501,7 +501,7 @@ class SwapManager(Logger):
|
||||
limits = pairs['pairs']['BTC/BTC']['limits']
|
||||
self._min_amount = limits['minimal']
|
||||
self._max_amount = limits['maximal']
|
||||
except:
|
||||
except Exception:
|
||||
self._min_amount = 10000
|
||||
self._max_amount = 10000000
|
||||
|
||||
|
||||
@@ -1195,18 +1195,18 @@ def convert_raw_tx_to_hex(raw: Union[str, bytes]) -> str:
|
||||
# try hex
|
||||
try:
|
||||
return binascii.unhexlify(raw).hex()
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
# try base43
|
||||
try:
|
||||
return base_decode(raw, base=43).hex()
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
# try base64
|
||||
if raw[0:6] in ('cHNidP', b'cHNidP'): # base64 psbt
|
||||
try:
|
||||
return base64.b64decode(raw).hex()
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
# raw bytes (do not strip whitespaces in this case)
|
||||
if isinstance(raw_unstripped, bytes):
|
||||
|
||||
+4
-4
@@ -432,7 +432,7 @@ def json_encode(obj):
|
||||
def json_decode(x):
|
||||
try:
|
||||
return json.loads(x, parse_float=Decimal)
|
||||
except:
|
||||
except Exception:
|
||||
return x
|
||||
|
||||
def json_normalize(x):
|
||||
@@ -562,7 +562,7 @@ def assert_bytes(*args):
|
||||
try:
|
||||
for x in args:
|
||||
assert isinstance(x, (bytes, bytearray))
|
||||
except:
|
||||
except Exception:
|
||||
print('assert bytes failed', list(map(type, args)))
|
||||
raise
|
||||
|
||||
@@ -646,7 +646,7 @@ def is_hex_str(text: Any) -> bool:
|
||||
if not isinstance(text, str): return False
|
||||
try:
|
||||
b = bytes.fromhex(text)
|
||||
except:
|
||||
except Exception:
|
||||
return False
|
||||
# forbid whitespaces in text:
|
||||
if len(text) != 2 * len(b):
|
||||
@@ -1191,7 +1191,7 @@ def parse_json(message):
|
||||
return None, message
|
||||
try:
|
||||
j = json.loads(message[0:n].decode('utf8'))
|
||||
except:
|
||||
except Exception:
|
||||
j = None
|
||||
return j, message[n+1:]
|
||||
|
||||
|
||||
@@ -169,7 +169,7 @@ class SPV(NetworkJobOnDefaultServer):
|
||||
tx = Transaction(raw_tx)
|
||||
try:
|
||||
tx.deserialize()
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
raise InnerNodeOfSpvProofIsValidTx()
|
||||
|
||||
+6
-6
@@ -653,7 +653,7 @@ class Abstract_Wallet(ABC, Logger, EventListener):
|
||||
text_dec = Decimal(text)
|
||||
text_dec_rounded = Decimal(fx.ccy_amount_str(text_dec, add_thousands_sep=False))
|
||||
reset = text_dec_rounded == def_fiat_rounded
|
||||
except:
|
||||
except Exception:
|
||||
# garbage. not resetting, but not saving either
|
||||
return False
|
||||
if reset:
|
||||
@@ -673,7 +673,7 @@ class Abstract_Wallet(ABC, Logger, EventListener):
|
||||
fiat_value = self.fiat_value.get(ccy, {}).get(txid)
|
||||
try:
|
||||
return Decimal(fiat_value)
|
||||
except:
|
||||
except Exception:
|
||||
return
|
||||
|
||||
def is_mine(self, address) -> bool:
|
||||
@@ -840,7 +840,7 @@ class Abstract_Wallet(ABC, Logger, EventListener):
|
||||
try:
|
||||
self.cpfp(tx, 0)
|
||||
can_cpfp = True
|
||||
except:
|
||||
except Exception:
|
||||
can_cpfp = False
|
||||
else:
|
||||
status = _('Local')
|
||||
@@ -1107,7 +1107,7 @@ class Abstract_Wallet(ABC, Logger, EventListener):
|
||||
for x in data:
|
||||
try:
|
||||
req = Request(**x)
|
||||
except:
|
||||
except Exception:
|
||||
raise FileImportFailed(_("Invalid invoice format"))
|
||||
self.add_payment_request(req, write_to_disk=False)
|
||||
self.save_db()
|
||||
@@ -1121,7 +1121,7 @@ class Abstract_Wallet(ABC, Logger, EventListener):
|
||||
for x in data:
|
||||
try:
|
||||
invoice = Invoice(**x)
|
||||
except:
|
||||
except Exception:
|
||||
raise FileImportFailed(_("Invalid invoice format"))
|
||||
self.save_invoice(invoice, write_to_disk=False)
|
||||
self.save_db()
|
||||
@@ -3460,7 +3460,7 @@ class Simple_Deterministic_Wallet(Simple_Wallet, Deterministic_Wallet):
|
||||
self.keystore = load_keystore(self.db, 'keystore') # type: KeyStoreWithMPK
|
||||
try:
|
||||
xtype = bip32.xpub_type(self.keystore.xpub)
|
||||
except:
|
||||
except Exception:
|
||||
xtype = 'standard'
|
||||
self.txin_type = 'p2pkh' if xtype == 'standard' else xtype
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ class WalletDB(JsonDB):
|
||||
def load_data(self, s):
|
||||
try:
|
||||
self.data = json.loads(s)
|
||||
except:
|
||||
except Exception:
|
||||
try:
|
||||
d = ast.literal_eval(s)
|
||||
labels = d.get('labels', {})
|
||||
@@ -109,7 +109,7 @@ class WalletDB(JsonDB):
|
||||
try:
|
||||
json.dumps(key)
|
||||
json.dumps(value)
|
||||
except:
|
||||
except Exception:
|
||||
self.logger.info(f'Failed to convert label to json format: {key}')
|
||||
continue
|
||||
self.data[key] = value
|
||||
|
||||
Reference in New Issue
Block a user