From 61b957ac779741a53531fe1bb4b1c298db369c49 Mon Sep 17 00:00:00 2001 From: Simone Margaritelli Date: Thu, 24 Oct 2019 17:23:33 +0200 Subject: [PATCH] fix: prevent user contributed plugins to crash the main process while loading --- pwnagotchi/plugins/__init__.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/pwnagotchi/plugins/__init__.py b/pwnagotchi/plugins/__init__.py index b221974..d080531 100644 --- a/pwnagotchi/plugins/__init__.py +++ b/pwnagotchi/plugins/__init__.py @@ -35,14 +35,18 @@ def load_from_file(filename): def load_from_path(path, enabled=()): global loaded for filename in glob.glob(os.path.join(path, "*.py")): - name, plugin = load_from_file(filename) - if name in loaded: - raise Exception("plugin %s already loaded from %s" % (name, plugin.__file__)) - elif name not in enabled: - # print("plugin %s is not enabled" % name) - pass - else: - loaded[name] = plugin + try: + name, plugin = load_from_file(filename) + if name in loaded: + raise Exception("plugin %s already loaded from %s" % (name, plugin.__file__)) + elif name not in enabled: + # print("plugin %s is not enabled" % name) + pass + else: + loaded[name] = plugin + except Exception as e: + logging.warning("error while loading %s: %s" % (filename, e)) + logging.debug(e, exc_info=True) return loaded