From 2eb02931aea1d4bf0c869284959bdb9b584f19f4 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Mon, 11 Jan 2021 00:05:23 +0100 Subject: [PATCH] hw plugins: log exception at import time (but only if interesting) related: https://github.com/spesmilo/electrum/issues/6928 --- electrum/plugins/bitbox02/bitbox02.py | 10 ++++++---- electrum/plugins/coldcard/coldcard.py | 4 +++- electrum/plugins/ledger/ledger.py | 4 +++- electrum/plugins/trezor/trezor.py | 3 ++- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/electrum/plugins/bitbox02/bitbox02.py b/electrum/plugins/bitbox02/bitbox02.py index ff09fef5e..c328a1d4c 100644 --- a/electrum/plugins/bitbox02/bitbox02.py +++ b/electrum/plugins/bitbox02/bitbox02.py @@ -25,6 +25,9 @@ import electrum.ecc as ecc from ..hw_wallet import HW_PluginBase, HardwareClientBase +_logger = get_logger(__name__) + + try: from bitbox02 import bitbox02 from bitbox02 import util @@ -36,13 +39,12 @@ try: FirmwareVersionOutdatedException, ) requirements_ok = True -except ImportError: +except ImportError as e: + if not (isinstance(e, ModuleNotFoundError) and e.name == 'bitbox02'): + _logger.exception('error importing bitbox02 plugin deps') requirements_ok = False -_logger = get_logger(__name__) - - class BitBox02Client(HardwareClientBase): # handler is a BitBox02_Handler, importing it would lead to a circular dependency def __init__(self, handler: Any, device: Device, config: SimpleConfig, *, plugin: HW_PluginBase): diff --git a/electrum/plugins/coldcard/coldcard.py b/electrum/plugins/coldcard/coldcard.py index b09e02407..73e9eb4bc 100644 --- a/electrum/plugins/coldcard/coldcard.py +++ b/electrum/plugins/coldcard/coldcard.py @@ -49,7 +49,9 @@ try: except: return False -except ImportError: +except ImportError as e: + if not (isinstance(e, ModuleNotFoundError) and e.name == 'ckcc'): + _logger.exception('error importing coldcard plugin deps') requirements_ok = False COINKITE_VID = 0xd13e diff --git a/electrum/plugins/ledger/ledger.py b/electrum/plugins/ledger/ledger.py index a19b28375..27a474de9 100644 --- a/electrum/plugins/ledger/ledger.py +++ b/electrum/plugins/ledger/ledger.py @@ -35,7 +35,9 @@ try: from btchip.btchipException import BTChipException BTCHIP = True BTCHIP_DEBUG = False -except ImportError: +except ImportError as e: + if not (isinstance(e, ModuleNotFoundError) and e.name == 'btchip'): + _logger.exception('error importing ledger plugin deps') BTCHIP = False MSG_NEEDS_FW_UPDATE_GENERIC = _('Firmware version too old. Please update at') + \ diff --git a/electrum/plugins/trezor/trezor.py b/electrum/plugins/trezor/trezor.py index 4911ce1d7..5b0941c77 100644 --- a/electrum/plugins/trezor/trezor.py +++ b/electrum/plugins/trezor/trezor.py @@ -36,7 +36,8 @@ try: TREZORLIB = True except Exception as e: - _logger.exception('error importing trezorlib') + if not (isinstance(e, ModuleNotFoundError) and e.name == 'trezorlib'): + _logger.exception('error importing trezor plugin deps') TREZORLIB = False class _EnumMissing: