mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-23 07:10:55 +00:00
Better error catching for broken packages
This commit is contained in:
@ -177,27 +177,31 @@ def get_modules(pkg, path=None):
|
|||||||
elif type(path) is not list:
|
elif type(path) is not list:
|
||||||
path = [path]
|
path = [path]
|
||||||
|
|
||||||
for finder, name, _ in pkgutil.walk_packages(path):
|
try:
|
||||||
try:
|
for finder, name, _ in pkgutil.walk_packages(path):
|
||||||
if sys.version_info < (3, 12):
|
try:
|
||||||
module = finder.find_module(name).load_module(name)
|
if sys.version_info < (3, 12):
|
||||||
else:
|
module = finder.find_module(name).load_module(name)
|
||||||
spec = finder.find_spec(name)
|
else:
|
||||||
module = module_from_spec(spec)
|
spec = finder.find_spec(name)
|
||||||
sys.modules[name] = module
|
module = module_from_spec(spec)
|
||||||
spec.loader.exec_module(module)
|
sys.modules[name] = module
|
||||||
pkg_names = getattr(module, '__all__', None)
|
spec.loader.exec_module(module)
|
||||||
for k, v in vars(module).items():
|
pkg_names = getattr(module, '__all__', None)
|
||||||
if not k.startswith('_') and (pkg_names is None or k in pkg_names):
|
for k, v in vars(module).items():
|
||||||
context[k] = v
|
if not k.startswith('_') and (pkg_names is None or k in pkg_names):
|
||||||
context[name] = module
|
context[k] = v
|
||||||
except AppRegistryNotReady: # pragma: no cover
|
context[name] = module
|
||||||
pass
|
except AppRegistryNotReady: # pragma: no cover
|
||||||
except Exception as error:
|
pass
|
||||||
# this 'protects' against malformed plugin modules by more or less silently failing
|
except Exception as error:
|
||||||
|
# this 'protects' against malformed plugin modules by more or less silently failing
|
||||||
|
|
||||||
# log to stack
|
# log to stack
|
||||||
log_error({name: str(error)}, 'discovery')
|
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()]
|
return [v for k, v in context.items()]
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user