This commit is contained in:
2026-01-31 19:57:09 -08:00
parent 6513a3ad04
commit 1dbaabac73
7 changed files with 125 additions and 88 deletions

View File

@@ -3,6 +3,8 @@ from __future__ import annotations
from importlib import import_module
from types import ModuleType
from typing import Any, Dict, List, Optional
import logging
logger = logging.getLogger(__name__)
try:
from .config import get_local_storage_path
@@ -31,7 +33,8 @@ def _get_cmdlet_package() -> Optional[ModuleType]:
return _cmdlet_pkg
try:
_cmdlet_pkg = import_module("cmdlet")
except Exception:
except Exception as exc:
logger.exception("Failed to import cmdlet package: %s", exc)
_cmdlet_pkg = None
return _cmdlet_pkg
@@ -52,8 +55,8 @@ def ensure_registry_loaded(force: bool = False) -> None:
if callable(ensure_fn):
try:
ensure_fn(force=force)
except Exception:
pass
except Exception as exc:
logger.exception("ensure_registry_loaded: ensure_cmdlet_modules_loaded failed: %s", exc)
def _normalize_mod_name(mod_name: str) -> str:
@@ -76,7 +79,8 @@ def import_cmd_module(mod_name: str):
return import_module(qualified)
except ModuleNotFoundError:
continue
except Exception:
except Exception as exc:
logger.exception("Unexpected error importing module %s: %s", qualified, exc)
continue
return None
@@ -127,7 +131,8 @@ def get_cmdlet_metadata(
if owner_mod:
owner = import_module(owner_mod)
data = getattr(owner, "CMDLET", None)
except Exception:
except Exception as exc:
logger.exception("Registry fallback failed while resolving cmdlet %s: %s", cmd_name, exc)
data = None
if not data:
@@ -303,14 +308,16 @@ def get_cmdlet_arg_choices(
from SYS.config import load_config
config = load_config()
except Exception:
except Exception as exc:
logger.exception("Failed to load config for matrix default choices: %s", exc)
config = config or {}
matrix_conf = {}
try:
providers = config.get("provider") or {}
matrix_conf = providers.get("matrix") or {}
except Exception:
except Exception as exc:
logger.exception("Failed to read matrix provider config: %s", exc)
matrix_conf = {}
raw = None
@@ -328,7 +335,8 @@ def get_cmdlet_arg_choices(
import re
ids = [p.strip() for p in re.split(r"[,\s]+", text) if p and p.strip()]
except Exception:
except Exception as exc:
logger.exception("Failed to parse matrix room ids from config: %r", raw)
ids = []
if ids:
@@ -350,12 +358,12 @@ def get_cmdlet_arg_choices(
choices.append(name or rid)
if choices:
return choices
except Exception:
pass
except Exception:
pass
except Exception:
pass
except Exception as exc:
logger.exception("Matrix provider failed while listing rooms: %s", exc)
except Exception as exc:
logger.exception("Failed to import Matrix provider or initialize: %s", exc)
except Exception as exc:
logger.exception("Failed to resolve matrix rooms: %s", exc)
# Fallback: return raw ids as choices
return ids