Don't crash when plugins fail to load.

This commit is contained in:
Sleepy Monax 2024-01-04 13:03:01 +01:00
parent 3e8c2f94ff
commit 78130b4f7f
4 changed files with 13 additions and 6 deletions

View file

@ -10,8 +10,8 @@ from . import (
model,
plugins,
pods, # noqa: F401 this is imported for side effects
vt100,
shell,
vt100,
)

View file

@ -240,15 +240,15 @@ def link(
if scope.component.type == model.Kind.LIB:
w.build(out, "ar", objs, implicit=res)
else:
whileLibs = collectInjectedLibs(scope)
wholeLibs = collectInjectedLibs(scope)
libs = collectLibs(scope)
w.build(
out,
"ld",
objs + whileLibs + libs,
objs + wholeLibs + libs,
variables={
"objs": " ".join(objs),
"wholeLibs": " ".join(whileLibs),
"wholeLibs": " ".join(wholeLibs),
"libs": " ".join(libs),
},
implicit=res,

View file

@ -120,6 +120,8 @@ def usage(args: Optional[Args] = None):
def error(msg: str) -> None:
print(f"{vt100.RED}Error:{vt100.RESET} {msg}\n", file=sys.stderr)
def warning(msg: str) -> None:
print(f"{vt100.YELLOW}Warning:{vt100.RESET} {msg}\n", file=sys.stderr)
@command("h", "help", "Show this help message")
def helpCmd(args: Args):

View file

@ -15,11 +15,15 @@ def load(path: str):
if not spec or not spec.loader:
_logger.error(f"Failed to load plugin {path}")
return None
module = importlib.module_from_spec(spec)
sys.modules["plugin"] = module
spec.loader.exec_module(module)
try:
spec.loader.exec_module(module)
except Exception as e:
_logger.error(f"Failed to load plugin {path}: {e}")
cli.warning(f"Plugin {path} loading skipped due to error")
def loadAll():
@ -35,6 +39,7 @@ def loadAll():
for dirname in paths:
pluginDir = os.path.join(project.dirname(), dirname, const.META_DIR, "plugins")
pluginDir = os.path.normpath(pluginDir)
initFile = os.path.join(pluginDir, "__init__.py")
if os.path.isfile(initFile):