Improve plugin error handling

master
Arinerron 2018-04-21 17:37:20 -07:00
parent 9cf07355ce
commit c0e08eae79
No known key found for this signature in database
GPG Key ID: 99383627861C62F0
2 changed files with 7 additions and 1 deletions

View File

@ -101,12 +101,15 @@ class Onionr:
os.mkdir('data/blocks/') os.mkdir('data/blocks/')
# Copy default plugins into plugins folder # Copy default plugins into plugins folder
if not os.path.exists('data/plugins/'):
if os.path.exists('default-plugins/'): if os.path.exists('default-plugins/'):
names = [f for f in os.listdir("default-plugins/") if not os.path.isfile(f)] names = [f for f in os.listdir("default-plugins/") if not os.path.isfile(f)]
shutil.copytree('default-plugins/', 'data/plugins/') shutil.copytree('default-plugins/', 'data/plugins/')
# Enable plugins # Enable plugins
for name in names: for name in names:
if not name in plugins.get_enabled_plugins():
plugins.enable(name, self) plugins.enable(name, self)
if not os.path.exists(self.onionrCore.peerDB): if not os.path.exists(self.onionrCore.peerDB):

View File

@ -31,6 +31,9 @@ def event(event_name, data = {}, onionr = None):
for plugin in plugins.get_enabled_plugins(): for plugin in plugins.get_enabled_plugins():
try: try:
call(plugins.get_plugin(plugin), event_name, data, get_pluginapi(onionr, data)) 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: except Exception as e:
logger.warn('Event \"' + event_name + '\" failed for plugin \"' + plugin + '\".') logger.warn('Event \"' + event_name + '\" failed for plugin \"' + plugin + '\".')
logger.debug(str(e)) logger.debug(str(e))