mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-06-17 02:05:22 -04:00
fix(cookbook): don't 500 the packages panel when an optional package crashes on import (#2618)
list_packages() probes each optional package with importlib.import_module() but only caught ImportError / PackageNotFoundError. A package that is installed yet raises a different exception on import took down the whole panel with a 500, surfaced in the UI as "Error loading packages: Unexpected token 'I', ...". Concrete Windows case: a CUDA build of llama-cpp-python runs os.add_dll_directory(r"...\CUDA\v12.3\bin") at import and raises FileNotFoundError when that toolkit dir is absent. Catch any exception during the import probe and report the package as not-installed instead of failing the entire request. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1209,6 +1209,12 @@ def setup_shell_routes() -> APIRouter:
|
|||||||
pkg["installed"] = False
|
pkg["installed"] = False
|
||||||
except importlib_metadata.PackageNotFoundError:
|
except importlib_metadata.PackageNotFoundError:
|
||||||
pkg["installed"] = False
|
pkg["installed"] = False
|
||||||
|
except Exception:
|
||||||
|
# Installed but crashes on import — e.g. a CUDA build of
|
||||||
|
# llama-cpp-python raising FileNotFoundError when the CUDA
|
||||||
|
# toolkit dir is absent. One broken optional package must not
|
||||||
|
# 500 the entire packages panel; report it as not usable.
|
||||||
|
pkg["installed"] = False
|
||||||
|
|
||||||
if pkg.get("installed"):
|
if pkg.get("installed"):
|
||||||
update_status = _package_pip_update_status(pkg, probe)
|
update_status = _package_pip_update_status(pkg, probe)
|
||||||
|
|||||||
Reference in New Issue
Block a user