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, model,
plugins, plugins,
pods, # noqa: F401 this is imported for side effects pods, # noqa: F401 this is imported for side effects
vt100,
shell, shell,
vt100,
) )

View file

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

View file

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

View file

@ -15,11 +15,15 @@ def load(path: str):
if not spec or not spec.loader: if not spec or not spec.loader:
_logger.error(f"Failed to load plugin {path}") _logger.error(f"Failed to load plugin {path}")
return None
module = importlib.module_from_spec(spec) module = importlib.module_from_spec(spec)
sys.modules["plugin"] = module sys.modules["plugin"] = module
try:
spec.loader.exec_module(module) 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(): def loadAll():
@ -35,6 +39,7 @@ def loadAll():
for dirname in paths: for dirname in paths:
pluginDir = os.path.join(project.dirname(), dirname, const.META_DIR, "plugins") pluginDir = os.path.join(project.dirname(), dirname, const.META_DIR, "plugins")
pluginDir = os.path.normpath(pluginDir)
initFile = os.path.join(pluginDir, "__init__.py") initFile = os.path.join(pluginDir, "__init__.py")
if os.path.isfile(initFile): if os.path.isfile(initFile):