mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-14 11:05:41 +00:00
rename
This commit is contained in:
@ -50,7 +50,7 @@ class MixinNotImplementedError(NotImplementedError):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def handle_plugin_error(error, do_raise: bool = True, do_log: bool = True, do_return: bool = False, log_name: str = ''):
|
def handle_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
|
Handles an error and casts it as an IntegrationPluginError
|
||||||
"""
|
"""
|
||||||
|
@ -15,7 +15,7 @@ def iter_namespace(pkg):
|
|||||||
|
|
||||||
def get_modules(pkg, recursive: bool = False):
|
def get_modules(pkg, recursive: bool = False):
|
||||||
"""get all modules in a package"""
|
"""get all modules in a package"""
|
||||||
from plugin.helpers import log_plugin_error
|
from plugin.helpers import log_error
|
||||||
|
|
||||||
if not recursive:
|
if not recursive:
|
||||||
return [importlib.import_module(name) for finder, name, ispkg in iter_namespace(pkg)]
|
return [importlib.import_module(name) for finder, name, ispkg in iter_namespace(pkg)]
|
||||||
@ -35,7 +35,7 @@ def get_modules(pkg, recursive: bool = False):
|
|||||||
# this 'protects' against malformed plugin modules by more or less silently failing
|
# this 'protects' against malformed plugin modules by more or less silently failing
|
||||||
|
|
||||||
# log to stack
|
# log to stack
|
||||||
log_plugin_error({name: str(error)}, 'discovery')
|
log_error({name: str(error)}, 'discovery')
|
||||||
|
|
||||||
return [v for k, v in context.items()]
|
return [v for k, v in context.items()]
|
||||||
|
|
||||||
|
@ -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 handle_plugin_error, IntegrationPluginError
|
from .helpers import handle_error, IntegrationPluginError
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger('inventree')
|
logger = logging.getLogger('inventree')
|
||||||
@ -67,7 +67,7 @@ class PluginsRegistry:
|
|||||||
Load and activate all IntegrationPlugins
|
Load and activate all IntegrationPlugins
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from plugin.helpers import log_plugin_error
|
from plugin.helpers import log_error
|
||||||
|
|
||||||
logger.info('Start loading plugins')
|
logger.info('Start loading plugins')
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ class PluginsRegistry:
|
|||||||
break
|
break
|
||||||
except IntegrationPluginError as error:
|
except IntegrationPluginError as error:
|
||||||
logger.error(f'[PLUGIN] Encountered an error with {error.path}:\n{error.message}')
|
logger.error(f'[PLUGIN] Encountered an error with {error.path}:\n{error.message}')
|
||||||
log_plugin_error({error.path: error.message}, 'load')
|
log_error({error.path: error.message}, 'load')
|
||||||
blocked_plugin = error.path # we will not try to load this app again
|
blocked_plugin = error.path # we will not try to load this app again
|
||||||
|
|
||||||
# Initialize apps without any integration plugins
|
# Initialize apps without any integration plugins
|
||||||
@ -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:
|
||||||
handle_plugin_error(error, do_raise=False, log_name='discovery')
|
handle_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
|
||||||
handle_plugin_error(error, log_name='init')
|
handle_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:
|
||||||
handle_plugin_error(error)
|
handle_error(error)
|
||||||
# endregion
|
# endregion
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user