From 7782a22f3843040ad3dbaed0dd7b9185ef314184 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 21 Nov 2021 23:46:54 +0100 Subject: [PATCH] make plugin init safe --- InvenTree/plugin/registry.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/InvenTree/plugin/registry.py b/InvenTree/plugin/registry.py index 1b693c8c5b..1b770948d2 100644 --- a/InvenTree/plugin/registry.py +++ b/InvenTree/plugin/registry.py @@ -200,7 +200,19 @@ class Plugins: # now we can be sure that an admin has activated the plugin -> as of Nov 2021 there are not many checks in place # but we could enhance those to check signatures, run the plugin against a whitelist etc. logger.info(f'Loading integration plugin {plugin.PLUGIN_NAME}') - plugin = plugin() + try: + plugin = plugin() + except Exception as error: + # log error + get_plugin_error(error, do_log=True, log_name='init') + + plugin_db_setting.active = False + # TODO save the error to the plugin + plugin_db_setting.save() + + # add to incative plugins + self.plugins_inactive[plug_key] = plugin_db_setting + logger.info(f'Loaded integration plugin {plugin.slug}') plugin.is_package = was_packaged if plugin_db_setting: