diff options
author | mathieui <mathieui@mathieui.net> | 2019-08-22 16:22:57 +0200 |
---|---|---|
committer | mathieui <mathieui@mathieui.net> | 2019-08-22 16:22:57 +0200 |
commit | 5312382f8abf228a9dcd83aec260ae2d939fc200 (patch) | |
tree | b46d1f3c7c45f008cdf3355a1c360067471112d2 | |
parent | 22ab7622f6557cbdb41e533de697dcd48a7db3dd (diff) | |
download | poezio-5312382f8abf228a9dcd83aec260ae2d939fc200.tar.gz poezio-5312382f8abf228a9dcd83aec260ae2d939fc200.tar.bz2 poezio-5312382f8abf228a9dcd83aec260ae2d939fc200.tar.xz poezio-5312382f8abf228a9dcd83aec260ae2d939fc200.zip |
Adapt the plugin safety metaclass for async funcs
-rw-r--r-- | poezio/plugin.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/poezio/plugin.py b/poezio/plugin.py index 0275e2f9..1995d7cd 100644 --- a/poezio/plugin.py +++ b/poezio/plugin.py @@ -3,6 +3,7 @@ Define the PluginConfig and Plugin classes, plus the SafetyMetaclass. These are used in the plugin system added in poezio 0.7.5 (see plugin_manager.py) """ +from asyncio import iscoroutinefunction from functools import partial from configparser import RawConfigParser from poezio.timed_events import TimedEvent, DelayedEvent @@ -84,9 +85,22 @@ class SafetyMetaclass(type): SafetyMetaclass.core.information(traceback.format_exc(), 'Error') return None - + async def async_helper(*args, **kwargs): + try: + return await f(*args, **kwargs) + except: + if inspect.stack()[1][1] == inspect.getfile(f): + raise + elif SafetyMetaclass.core: + log.error('Error in a plugin', exc_info=True) + SafetyMetaclass.core.information(traceback.format_exc(), + 'Error') + return None + if iscoroutinefunction(f): + return async_helper return helper + def __new__(meta, name, bases, class_dict): for k, v in class_dict.items(): if inspect.isfunction(v): |