Commit e3859c28 authored by mathieui's avatar mathieui

Do not load a plugin if its init() traceback

and show a somehow helpful error message in this case
parent 9c2203e7
......@@ -10,6 +10,8 @@ from timed_events import TimedEvent, DelayedEvent
import config
import inspect
import traceback
import logging
log = logging.getLogger(__name__)
class PluginConfig(config.Config):
"""
......@@ -81,7 +83,8 @@ class SafetyMetaclass(type):
def __new__(meta, name, bases, class_dict):
for k, v in class_dict.items():
if inspect.isfunction(v):
class_dict[k] = SafetyMetaclass.safe_func(v)
if k != '__init__' and k != 'init':
class_dict[k] = SafetyMetaclass.safe_func(v)
return type.__new__(meta, name, bases, class_dict)
class PluginWrap(object):
......
......@@ -92,10 +92,17 @@ class PluginManager(object):
self.tab_keys[name] = {}
self.tab_commands[name] = {}
self.event_handlers[name] = []
self.plugins[name] = module.Plugin(self.plugin_api, self.core, self.plugins_conf_dir)
if notify:
self.core.information('Plugin %s loaded' % name, 'Info')
try:
self.plugins[name] = None
self.plugins[name] = module.Plugin(self.plugin_api, self.core, self.plugins_conf_dir)
except Exception as e:
log.error('Error while loading the plugin %s', name, exc_info=True)
if notify:
self.core.information('Unable to load the plugin %s: %s' % (name, e), 'Error')
self.unload(name, notify=False)
else:
if notify:
self.core.information('Plugin %s loaded' % name, 'Info')
def unload(self, name, notify=True):
if name in self.plugins:
......@@ -115,7 +122,8 @@ class PluginManager(object):
for event_name, handler in self.event_handlers[name][:]:
self.del_event_handler(name, event_name, handler)
self.plugins[name].unload()
if self.plugins[name] is not None:
self.plugins[name].unload()
del self.plugins[name]
del self.commands[name]
del self.keys[name]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment