mirror of
https://github.com/inventree/InvenTree.git
synced 2025-08-02 18:11:42 +00:00
Improved exception handling for plugin loading
This commit is contained in:
@@ -177,8 +177,17 @@ def get_modules(pkg, path=None):
|
||||
elif type(path) is not list:
|
||||
path = [path]
|
||||
|
||||
packages = pkgutil.walk_packages(path)
|
||||
|
||||
while True:
|
||||
try:
|
||||
for finder, name, _ in pkgutil.walk_packages(path):
|
||||
finder, name, _ = next(packages)
|
||||
except StopIteration:
|
||||
break
|
||||
except Exception as error:
|
||||
log_error({pkg.__name__: str(error)}, 'discovery')
|
||||
continue
|
||||
|
||||
try:
|
||||
if sys.version_info < (3, 12):
|
||||
module = finder.find_module(name).load_module(name)
|
||||
@@ -199,19 +208,16 @@ def get_modules(pkg, path=None):
|
||||
|
||||
# log to stack
|
||||
log_error({name: str(error)}, 'discovery')
|
||||
except Exception as error:
|
||||
# log to stack
|
||||
log_error({pkg.__name__: str(error)}, 'discovery')
|
||||
|
||||
return [v for k, v in context.items()]
|
||||
|
||||
|
||||
def get_classes(module) -> list:
|
||||
"""Get all classes in a given module."""
|
||||
try:
|
||||
# try:
|
||||
return inspect.getmembers(module, inspect.isclass)
|
||||
except Exception:
|
||||
return []
|
||||
# except Exception:
|
||||
# return []
|
||||
|
||||
|
||||
def get_plugins(pkg, baseclass, path=None):
|
||||
|
Reference in New Issue
Block a user