mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 20:16:44 +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
|
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
|
package_path = traceback.extract_tb(error.__traceback__)[-1].filename
|
||||||
install_path = sysconfig.get_paths()["purelib"]
|
install_path = sysconfig.get_paths()["purelib"]
|
||||||
try:
|
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_kwargs['reference'] = log_name
|
||||||
log_plugin_error({package_name: str(error)}, **log_kwargs)
|
log_plugin_error({package_name: str(error)}, **log_kwargs)
|
||||||
|
|
||||||
|
new_error = IntegrationPluginError(package_name, str(error))
|
||||||
|
|
||||||
if do_raise:
|
if do_raise:
|
||||||
raise IntegrationPluginError(package_name, str(error))
|
raise IntegrationPluginError(package_name, str(error))
|
||||||
|
|
||||||
return package_name, str(error)
|
if do_return:
|
||||||
|
return new_error
|
||||||
# endregion
|
# endregion
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ from maintenance_mode.core import get_maintenance_mode, set_maintenance_mode
|
|||||||
|
|
||||||
from plugin import plugins as inventree_plugins
|
from plugin import plugins as inventree_plugins
|
||||||
from .integration import IntegrationPluginBase
|
from .integration import IntegrationPluginBase
|
||||||
from .helpers import get_plugin_error, IntegrationPluginError
|
from .helpers import handle_plugin_error, IntegrationPluginError
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger('inventree')
|
logger = logging.getLogger('inventree')
|
||||||
@ -180,7 +180,7 @@ class PluginsRegistry:
|
|||||||
plugin.is_package = True
|
plugin.is_package = True
|
||||||
self.plugin_modules.append(plugin)
|
self.plugin_modules.append(plugin)
|
||||||
except Exception as error:
|
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
|
# Log collected plugins
|
||||||
logger.info(f'Collected {len(self.plugin_modules)} plugins!')
|
logger.info(f'Collected {len(self.plugin_modules)} plugins!')
|
||||||
@ -259,7 +259,7 @@ class PluginsRegistry:
|
|||||||
plugin = plugin()
|
plugin = plugin()
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
# log error and raise it -> disable plugin
|
# 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}')
|
logger.info(f'Loaded integration plugin {plugin.slug}')
|
||||||
plugin.is_package = was_packaged
|
plugin.is_package = was_packaged
|
||||||
@ -543,7 +543,7 @@ class PluginsRegistry:
|
|||||||
cmd(*args, **kwargs)
|
cmd(*args, **kwargs)
|
||||||
return True, []
|
return True, []
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
get_plugin_error(error, do_raise=True)
|
handle_plugin_error(error)
|
||||||
# endregion
|
# endregion
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user