mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
change default values for plugin hadler
This commit is contained in:
parent
f53e66d4c3
commit
3ae84617d0
@ -44,7 +44,10 @@ class MixinNotImplementedError(NotImplementedError):
|
||||
pass
|
||||
|
||||
|
||||
def get_plugin_error(error, do_raise: bool = False, do_log: bool = False, log_name: str = ''):
|
||||
def handle_plugin_error(error, do_raise: bool = True, do_log: bool = True, do_return: bool = False, log_name: str = ''):
|
||||
"""
|
||||
Handles an error and casts it as an IntegrationPluginError
|
||||
"""
|
||||
package_path = traceback.extract_tb(error.__traceback__)[-1].filename
|
||||
install_path = sysconfig.get_paths()["purelib"]
|
||||
try:
|
||||
@ -70,10 +73,13 @@ def get_plugin_error(error, do_raise: bool = False, do_log: bool = False, log_na
|
||||
log_kwargs['reference'] = log_name
|
||||
log_plugin_error({package_name: str(error)}, **log_kwargs)
|
||||
|
||||
new_error = IntegrationPluginError(package_name, str(error))
|
||||
|
||||
if do_raise:
|
||||
raise IntegrationPluginError(package_name, str(error))
|
||||
|
||||
return package_name, str(error)
|
||||
if do_return:
|
||||
return new_error
|
||||
# endregion
|
||||
|
||||
|
||||
|
@ -30,7 +30,7 @@ from maintenance_mode.core import get_maintenance_mode, set_maintenance_mode
|
||||
|
||||
from plugin import plugins as inventree_plugins
|
||||
from .integration import IntegrationPluginBase
|
||||
from .helpers import get_plugin_error, IntegrationPluginError
|
||||
from .helpers import handle_plugin_error, IntegrationPluginError
|
||||
|
||||
|
||||
logger = logging.getLogger('inventree')
|
||||
@ -180,7 +180,7 @@ class PluginsRegistry:
|
||||
plugin.is_package = True
|
||||
self.plugin_modules.append(plugin)
|
||||
except Exception as error:
|
||||
get_plugin_error(error, do_log=True, log_name='discovery')
|
||||
handle_plugin_error(error, do_raise=False, log_name='discovery')
|
||||
|
||||
# Log collected plugins
|
||||
logger.info(f'Collected {len(self.plugin_modules)} plugins!')
|
||||
@ -259,7 +259,7 @@ class PluginsRegistry:
|
||||
plugin = plugin()
|
||||
except Exception as error:
|
||||
# log error and raise it -> disable plugin
|
||||
get_plugin_error(error, do_raise=True, do_log=True, log_name='init')
|
||||
handle_plugin_error(error, log_name='init')
|
||||
|
||||
logger.info(f'Loaded integration plugin {plugin.slug}')
|
||||
plugin.is_package = was_packaged
|
||||
@ -543,7 +543,7 @@ class PluginsRegistry:
|
||||
cmd(*args, **kwargs)
|
||||
return True, []
|
||||
except Exception as error:
|
||||
get_plugin_error(error, do_raise=True)
|
||||
handle_plugin_error(error)
|
||||
# endregion
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user