From dee402b961fb6a5ec8e3dba629487746b5c5258a Mon Sep 17 00:00:00 2001 From: Neil Booth Date: Sun, 24 Jan 2016 19:39:59 +0900 Subject: [PATCH] Plugin wallets: better error when unloadable Used to get: jsonrpclib.jsonrpc.ProtocolError: (-32603, u'Server error: File "src/electrum/lib/plugins.py", line 144, in wallet_plugin_loader | KeyError: \'trustedcoin\'') Now get: jsonrpclib.jsonrpc.ProtocolError: (-32603, u'Server error: File "src/electrum/lib/plugins.py", line 81, in load_plugin | RuntimeError: cmdline implementation for trustedcoin plugin not found') --- electrum | 1 - lib/plugins.py | 30 ++++++++++++++++++------------ plugins/trustedcoin/__init__.py | 2 +- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/electrum b/electrum index 1251949d0..60fef3e58 100755 --- a/electrum +++ b/electrum @@ -18,7 +18,6 @@ # along with this program. If not, see . from decimal import Decimal -import json import os import re import sys diff --git a/lib/plugins.py b/lib/plugins.py index 3b064a4cd..9a1c0578d 100644 --- a/lib/plugins.py +++ b/lib/plugins.py @@ -51,6 +51,8 @@ class Plugins(DaemonThread): m = loader.find_module(name).load_module(name) d = m.__dict__ gui_good = gui_name in d.get('available_for', []) + # We register wallet types even if the GUI isn't provided + # so that they can be restored in the install wizard details = d.get('registers_wallet_type') if details: self.register_plugin_wallet(name, gui_good, details) @@ -58,7 +60,12 @@ class Plugins(DaemonThread): continue self.descriptions[name] = d if not d.get('requires_wallet_type') and config.get('use_' + name): - self.load_plugin(name) + try: + self.load_plugin(name) + except BaseException as e: + traceback.print_exc(file=sys.stdout) + self.print_error("cannot initialize plugin %s:" % name, + str(e)) def get(self, name): return self.plugins.get(name) @@ -68,17 +75,16 @@ class Plugins(DaemonThread): def load_plugin(self, name): full_name = 'electrum_plugins.' + name + '.' + self.gui_name - try: - p = pkgutil.find_loader(full_name).load_module(full_name) - plugin = p.Plugin(self, self.config, name) - self.add_jobs(plugin.thread_jobs()) - self.plugins[name] = plugin - self.print_error("loaded", name) - return plugin - except Exception: - self.print_error("cannot initialize plugin", name) - traceback.print_exc(file=sys.stdout) - return None + loader = pkgutil.find_loader(full_name) + if not loader: + raise RuntimeError("%s implementation for %s plugin not found" + % (self.gui_name, name)) + p = loader.load_module(full_name) + plugin = p.Plugin(self, self.config, name) + self.add_jobs(plugin.thread_jobs()) + self.plugins[name] = plugin + self.print_error("loaded", name) + return plugin def close_plugin(self, plugin): self.remove_jobs(plugin.thread_jobs()) diff --git a/plugins/trustedcoin/__init__.py b/plugins/trustedcoin/__init__.py index 19e36d960..fee3c3dbc 100644 --- a/plugins/trustedcoin/__init__.py +++ b/plugins/trustedcoin/__init__.py @@ -8,4 +8,4 @@ description = ''.join([ ]) requires_wallet_type = ['2fa'] registers_wallet_type = ('twofactor', '2fa', _("Wallet with two-factor authentication")) -available_for = ['qt', 'cmdline'] +available_for = ['qt']