From c0e08eae794c1b20d8f88c57e56416b7147e8aa7 Mon Sep 17 00:00:00 2001 From: Arinerron Date: Sat, 21 Apr 2018 17:37:20 -0700 Subject: [PATCH] Improve plugin error handling --- onionr/onionr.py | 5 ++++- onionr/onionrevents.py | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/onionr/onionr.py b/onionr/onionr.py index 8e2f4888..a92eb77e 100755 --- a/onionr/onionr.py +++ b/onionr/onionr.py @@ -101,13 +101,16 @@ class Onionr: os.mkdir('data/blocks/') # Copy default plugins into plugins folder + + if not os.path.exists('data/plugins/'): if os.path.exists('default-plugins/'): names = [f for f in os.listdir("default-plugins/") if not os.path.isfile(f)] shutil.copytree('default-plugins/', 'data/plugins/') # Enable plugins for name in names: - plugins.enable(name, self) + if not name in plugins.get_enabled_plugins(): + plugins.enable(name, self) if not os.path.exists(self.onionrCore.peerDB): self.onionrCore.createPeerDB() diff --git a/onionr/onionrevents.py b/onionr/onionrevents.py index 61005b98..36ce1477 100644 --- a/onionr/onionrevents.py +++ b/onionr/onionrevents.py @@ -31,6 +31,9 @@ def event(event_name, data = {}, onionr = None): for plugin in plugins.get_enabled_plugins(): try: call(plugins.get_plugin(plugin), event_name, data, get_pluginapi(onionr, data)) + except ModuleNotFoundError as e: + logger.warn('Disabling nonexistant plugin \"' + plugin + '\"...') + plugins.disable(plugin, onionr, stop_event = False) except Exception as e: logger.warn('Event \"' + event_name + '\" failed for plugin \"' + plugin + '\".') logger.debug(str(e))