Improve plugin error handling

This commit is contained in:
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,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()

View File

@ -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))