run_hook: no more than one plugin shall return a result
[electrum-nvc.git] / lib / plugins.py
index e7687a6..feea2fc 100644 (file)
@@ -1,7 +1,7 @@
 from util import print_error
 import traceback, sys
-from electrum.util import *
-from electrum.i18n import _
+from util import *
+from i18n import _
 
 plugins = []
 
@@ -24,7 +24,7 @@ def init_plugins(self):
     for name, p in zip(plugin_names, plugin_modules):
         try:
             plugins.append( p.Plugin(self, name) )
-        except:
+        except Exception:
             print_msg(_("Error: cannot initialize plugin"),p)
             traceback.print_exc(file=sys.stdout)
 
@@ -34,6 +34,8 @@ def run_hook(name, *args):
     
     global plugins
 
+    results = []
+
     for p in plugins:
 
         if not p.is_enabled():
@@ -44,12 +46,17 @@ def run_hook(name, *args):
             continue
 
         try:
-            f(*args)
-        except:
+            r = f(*args)
+        except Exception:
             print_error("Plugin error")
             traceback.print_exc(file=sys.stdout)
-            
-    return
+
+        if r:
+            results.append(r)
+
+    if results:
+        assert len(results) == 1, results
+        return results[0]