From f02ba8004481e3a4578b48f3a4ed557a479092b8 Mon Sep 17 00:00:00 2001 From: exelchapo Date: Sat, 23 May 2026 01:25:05 +0800 Subject: [PATCH] fix: load_module crashes on missing or malformed spark.toml load_module() calls manifest_path.read_text() and tomllib.loads() without error handling. If spark.toml is missing, has permission issues, or contains invalid TOML, the function raises an unhandled exception that propagates as a raw traceback. Wrap in try/except with descriptive SystemExit messages for FileNotFoundError, PermissionError, and TOMLDecodeError. --- src/spark_cli/cli.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/spark_cli/cli.py b/src/spark_cli/cli.py index 5f32bd5d..1a0834c2 100644 --- a/src/spark_cli/cli.py +++ b/src/spark_cli/cli.py @@ -1941,7 +1941,14 @@ def save_json(path: Path, payload: Any) -> None: def load_module(path: Path) -> Module: manifest_path = path / "spark.toml" - manifest = tomllib.loads(manifest_path.read_text(encoding="utf-8")) + try: + manifest = tomllib.loads(manifest_path.read_text(encoding="utf-8")) + except FileNotFoundError: + raise SystemExit(f"Module manifest not found: {manifest_path}") + except PermissionError: + raise SystemExit(f"Permission denied reading module manifest: {manifest_path}") + except tomllib.TOMLDecodeError as exc: + raise SystemExit(f"Invalid TOML in module manifest {manifest_path}: {exc}") name = str(manifest.get("module", {}).get("name") or path.name) return Module(name=name, path=path, manifest=manifest)