mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
refactor plugin error processing definition
This commit is contained in:
parent
b05381fcc8
commit
71e05d569b
@ -3,8 +3,6 @@ from __future__ import unicode_literals
|
||||
import importlib
|
||||
import pathlib
|
||||
import logging
|
||||
import sysconfig
|
||||
import traceback
|
||||
from typing import OrderedDict
|
||||
from importlib import reload
|
||||
|
||||
@ -26,6 +24,7 @@ from maintenance_mode.core import get_maintenance_mode, set_maintenance_mode
|
||||
|
||||
from plugin import plugins as inventree_plugins
|
||||
from plugin.integration import IntegrationPluginBase
|
||||
from plugin.helpers import get_plugin_error
|
||||
|
||||
|
||||
logger = logging.getLogger('inventree')
|
||||
@ -416,9 +415,6 @@ class PluginAppConfig(AppConfig):
|
||||
cmd(*args, **kwargs)
|
||||
return True, []
|
||||
except Exception as error:
|
||||
package_path = traceback.extract_tb(error.__traceback__)[-1].filename
|
||||
install_path = sysconfig.get_paths()["purelib"]
|
||||
package_name = pathlib.Path(package_path).relative_to(install_path).parts[0]
|
||||
raise PluginLoadingError(package_name, str(error))
|
||||
raise PluginLoadingError(get_plugin_error(error))
|
||||
# endregion
|
||||
# endregion
|
||||
|
@ -1,4 +1,8 @@
|
||||
"""Helpers for plugin app"""
|
||||
import pathlib
|
||||
import sysconfig
|
||||
import traceback
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
@ -9,3 +13,9 @@ def log_plugin_error(error, reference: str = 'general'):
|
||||
|
||||
# add error to stack
|
||||
settings.INTEGRATION_ERRORS[reference].append(error)
|
||||
|
||||
def get_plugin_error(error):
|
||||
package_path = traceback.extract_tb(error.__traceback__)[-1].filename
|
||||
install_path = sysconfig.get_paths()["purelib"]
|
||||
package_name = pathlib.Path(package_path).relative_to(install_path).parts[0]
|
||||
return package_name, str(error)
|
||||
|
Loading…
Reference in New Issue
Block a user