mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-07 12:48:11 +08:00
Fix error handling in plugin module (#1645)
This commit is contained in:
+8
-1
@@ -1,6 +1,13 @@
|
|||||||
from server.common.utils import import_plugins
|
from server.common.utils import import_plugins
|
||||||
|
import logging
|
||||||
|
import sys
|
||||||
|
|
||||||
__version__ = "0.15.0"
|
__version__ = "0.15.0"
|
||||||
display_version = "cellxgene v" + __version__
|
display_version = "cellxgene v" + __version__
|
||||||
|
|
||||||
import_plugins("server.plugins")
|
try:
|
||||||
|
import_plugins("server.plugins")
|
||||||
|
except Exception as e:
|
||||||
|
# Make sure to exit in this case, as the server may not be configured as expected.
|
||||||
|
logging.critical(f"Error in import_plugins: {str(e)}")
|
||||||
|
sys.exit(1)
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ from flask import json
|
|||||||
from urllib.parse import urlsplit, urljoin
|
from urllib.parse import urlsplit, urljoin
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
from server.common.errors import ConfigurationError
|
||||||
|
|
||||||
|
|
||||||
def find_available_port(host, port=5005):
|
def find_available_port(host, port=5005):
|
||||||
@@ -161,10 +162,13 @@ def import_plugins(plugin_module):
|
|||||||
pkg = importlib.import_module(plugin_module)
|
pkg = importlib.import_module(plugin_module)
|
||||||
for loader, name, is_pkg in pkgutil.walk_packages(pkg.__path__):
|
for loader, name, is_pkg in pkgutil.walk_packages(pkg.__path__):
|
||||||
full_name = f"{plugin_module}.{name}"
|
full_name = f"{plugin_module}.{name}"
|
||||||
module = importlib.import_module(full_name)
|
try:
|
||||||
logging.info(f"Imported plugin {full_name}")
|
module = importlib.import_module(full_name)
|
||||||
|
except Exception as e:
|
||||||
|
raise ConfigurationError(f"Unexpected error while importing plugin: {plugin_module}.{name}: {str(e)}")
|
||||||
loaded_modules.append(module)
|
loaded_modules.append(module)
|
||||||
except ModuleNotFoundError as e:
|
except ModuleNotFoundError as e:
|
||||||
logging.error(f"No plugins found in module: {plugin_module}: {str(e)}")
|
# This exception occurs when the plugin_module does not exist (not an error).
|
||||||
|
logging.debug(f"No plugins found in module: {plugin_module}: {str(e)}")
|
||||||
|
|
||||||
return loaded_modules
|
return loaded_modules
|
||||||
|
|||||||
Reference in New Issue
Block a user