The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(hermes_cli): remaining try/except-pass blocks -> contextlib.suppress
Teknium28a987413d17
diff --git a/hermes_cli/main_dashboard.py b/hermes_cli/main_dashboard.pyindex c36cec43aa8..90058f828fe 100644--- a/hermes_cli/main_dashboard.py+++ b/hermes_cli/main_dashboard.py@@ -373,11 +373,9 @@ def _finalize_update_output(state):sys.stderr = state.get("prev_stderr", sys.stderr)log_file = state.get("log_file")if log_file is not None:- try:+ with contextlib.suppress(Exception):log_file.flush()log_file.close()- except Exception:- passdef _report_dashboard_status() -> int:@@ -662,11 +660,9 @@ def _route_named_profile_dashboard(print(f"Machine dashboard already running on port {args.port}.")print(f" Managing profile '{_launch_profile}': {url}")if not args.no_open:- try:+ with contextlib.suppress(Exception):import webbrowserwebbrowser.open(url)- except Exception:- passsys.exit(0)print(diff --git a/hermes_cli/main_desktop.py b/hermes_cli/main_desktop.pyindex f820cc5b70b..25367944a99 100644--- a/hermes_cli/main_desktop.py+++ b/hermes_cli/main_desktop.py@@ -484,21 +484,18 @@ def _purge_electron_build_cache(desktop_dir: Path, release_dir: Optional[Path] =if not cache_dir.is_dir():continuefor zip_path in sorted(cache_dir.rglob("electron-*.zip")):- try:+ # locked/permission-denied: let the build report its own error+ with contextlib.suppress(OSError):zip_path.unlink()removed.append(zip_path)- except OSError:- pass # locked/permission-denied: let the build report its own errorif release_dir is None:release_dir = desktop_dir / "release"if release_dir.is_dir():for unpacked in release_dir.glob("*-unpacked"):- try:+ with contextlib.suppress(OSError):shutil.rmtree(unpacked, ignore_errors=True)removed.append(unpacked)- except OSError:- passreturn removed@@ -626,15 +623,13 @@ def _stop_desktop_processes_locking_build(desktop_dir: Path) -> list[int]:continueif stopped:# Wait for the handles (and thus the file locks) to actually release.- try:+ with contextlib.suppress(Exception):_, alive = psutil.wait_procs(victims, timeout=5)for proc in alive:try:proc.kill()except Exception:continue- except Exception:- passreturn stopped@@ -902,11 +897,10 @@ def _macos_create_signing_identity(_export_p12([])imported = _import_p12()if imported.returncode != 0 and "MAC verification failed" in (imported.stderr or ""):- try:+ # older OpenSSL without -legacy: keep the original failure+ with contextlib.suppress(subprocess.CalledProcessError):_export_p12(["-legacy"])imported = _import_p12()- except subprocess.CalledProcessError:- pass # older OpenSSL without -legacy: keep the original failureif imported.returncode != 0:print(f" (could not import signing identity into keychain: {imported.stderr.strip()})")return False@@ -1132,7 +1126,7 @@ def _detect_linux_password_store() -> str | None:return "kwallet"if os.environ.get("GNOME_KEYRING_CONTROL"):return "gnome-libsecret"- try:+ with contextlib.suppress(Exception):result = subprocess.run(["dbus-send", "--session", "--print-reply", "--reply-timeout=2000",@@ -1144,8 +1138,6 @@ def _detect_linux_password_store() -> str | None:timeout=5)if result.returncode == 0:return "gnome-libsecret"- except Exception:- passreturn None@@ -1434,11 +1426,9 @@ def cmd_gui(args: argparse.Namespace):print(f"Desktop GUI source not found at: {desktop_dir}")sys.exit(1)- try:+ with contextlib.suppress(Exception):from hermes_logging import setup_logging as _setup_logging_gui_setup_logging_gui(mode="gui")- except Exception:- passenv, config_electron_flags = _desktop_launch_env(args)diff --git a/hermes_cli/main_tui_launch.py b/hermes_cli/main_tui_launch.pyindex d85b635f071..8c0e63601ee 100644--- a/hermes_cli/main_tui_launch.py+++ b/hermes_cli/main_tui_launch.py@@ -418,12 +418,10 @@ def _tui_node_bin(bin: str) -> str:from hermes_constants import find_node_executablepath = find_node_executable(bin)if not path and bin == "node":- try:+ with contextlib.suppress(Exception):from hermes_cli.dep_ensure import ensure_dependencyif ensure_dependency("node"):path = find_node_executable("node")- except Exception:- passif not path:print(f"{bin} not found — install Node.js to use the TUI.")sys.exit(1)@@ -764,11 +762,9 @@ def _launch_tui(with contextlib.suppress(OSError):os.unlink(active_session_file)if wt_info:- try:+ with contextlib.suppress(Exception):from cli import _cleanup_worktree_cleanup_worktree(wt_info)- except Exception:- pass# Exit code 42 = TUI requested an update. Relaunch as `hermes update`;# preserve_inherited=False keeps --tui and other flags out of the subcommand.@@ -785,21 +781,17 @@ def _pin_kanban_board_env() -> None:``hermes kanban`` calls agree even if a concurrent ``boards switch`` flips the file mid-turn."""if os.environ.get("HERMES_KANBAN_BOARD"):return- try:+ with contextlib.suppress(Exception):from hermes_cli.kanban_db import get_current_boardos.environ["HERMES_KANBAN_BOARD"] = get_current_board()- except Exception:- passdef _sync_bundled_skills_quietly() -> None:"""Seed ``~/.hermes/skills/`` with the bundled library (idempotent, milliseconds when synced).Failures are swallowed: skills are an enhancement, not a hard dependency."""- try:+ with contextlib.suppress(Exception):from tools.skills_sync import sync_skillssync_skills(quiet=True)- except Exception:- passdef _resolve_use_tui(args) -> bool:diff --git a/hermes_cli/main_web_build.py b/hermes_cli/main_web_build.pyindex bf083a51e9b..7cd47ae20a3 100644--- a/hermes_cli/main_web_build.py+++ b/hermes_cli/main_web_build.py@@ -8,6 +8,7 @@ avoids an import cycle)."""import logging+import contextlibimport hashlibimport jsonimport os@@ -98,12 +99,10 @@ def _hash_source_tree(project_root: Path, tree_dir: Path) -> str:def _hash_file(path: Path) -> None:h.update(str(path.relative_to(project_root)).encode())h.update(b"\0")- try:+ with contextlib.suppress(OSError):with open(path, "rb") as f:for chunk in iter(lambda: f.read(65536), b""):h.update(chunk)- except OSError:- passh.update(b"\0")from pathspec import PathSpec@@ -284,7 +283,8 @@ def _nixos_build_env() -> dict[str, str] | None:if venv_python.exists():return {**os.environ, "PYTHON": str(venv_python)}- try:+ # nix-shell not available — caller will get None+ with contextlib.suppress(Exception):result = subprocess.run(["nix-shell", "-p", "python3", "--run", "which python3"],capture_output=True, text=True, encoding="utf-8", errors="replace", check=False, timeout=15,@@ -293,8 +293,6 @@ def _nixos_build_env() -> dict[str, str] | None:python3_path = result.stdout.strip()if python3_path and Path(python3_path).exists():return {**os.environ, "PYTHON": python3_path}- except Exception:- pass # nix-shell not available — caller will get Nonereturn None