The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(hermes_cli): try/except-pass -> contextlib.suppress in desktop/dashboard/tui_launch
Teknium8a141af62f83
diff --git a/hermes_cli/main_dashboard.py b/hermes_cli/main_dashboard.pyindex 07c2840677f..78dba581f4f 100644--- a/hermes_cli/main_dashboard.py+++ b/hermes_cli/main_dashboard.py@@ -7,6 +7,7 @@ Names that stay in main are imported lazily inside the functions that use themavoids an import cycle)."""+import contextlibimport osimport reimport shlex@@ -247,10 +248,8 @@ def _respawn_dashboard_processes(commands: list[list[str]]) -> list[list[str]]:respawned: list[list[str]] = []failed: list[tuple[list[str], str]] = []log_path = get_hermes_home() / "logs" / "dashboard-restart.log"- try:+ with contextlib.suppress(OSError):log_path.parent.mkdir(parents=True, exist_ok=True)- except OSError:- passfor command in commands:try:@@ -287,10 +286,8 @@ class _UpdateOutputStream:def write(self, data):# Mirror to the log file first — it's the most reliable destination.if self._log is not None:- try:+ with contextlib.suppress(Exception):self._log.write(data)- except Exception:- passif not self._original_broken:try:return self._original.write(data)@@ -300,10 +297,8 @@ class _UpdateOutputStream:def flush(self):if self._log is not None:- try:+ with contextlib.suppress(Exception):self._log.flush()- except Exception:- passif self._original_broken:returntry:@@ -340,10 +335,9 @@ def _install_hangup_protection(gateway_mode: bool = False):import signal as _signalif hasattr(_signal, "SIGHUP"):- try:+ # Non-main thread: update still runs, just without hangup protection.+ with contextlib.suppress(ValueError, OSError):_signal.signal(_signal.SIGHUP, _signal.SIG_IGN)- except (ValueError, OSError):- pass # non-main thread — update still runs, just without hangup protection# Any failure here is non-fatal; we just skip the wrap.try:@@ -373,14 +367,10 @@ def _finalize_update_output(state):if not state:returnif state.get("installed"):- try:+ with contextlib.suppress(Exception):sys.stdout = state.get("prev_stdout", sys.stdout)- except Exception:- pass- try:+ with contextlib.suppress(Exception):sys.stderr = state.get("prev_stderr", sys.stderr)- except Exception:- passlog_file = state.get("log_file")if log_file is not None:try:@@ -624,10 +614,8 @@ def _read_ssh_session_token_file(path: str) -> str:if file_fd >= 0:os.close(file_fd)if directory_fd >= 0:- try:+ with contextlib.suppress(OSError):os.unlink(relative.parts[1], dir_fd=directory_fd)- except OSError:- passos.close(directory_fd)if root_fd >= 0:os.close(root_fd)diff --git a/hermes_cli/main_desktop.py b/hermes_cli/main_desktop.pyindex 301add161e5..441c8af2a7e 100644--- a/hermes_cli/main_desktop.py+++ b/hermes_cli/main_desktop.py@@ -8,6 +8,7 @@ avoids an import cycle)."""import logging+import contextlibimport argparseimport osimport re@@ -424,10 +425,8 @@ def _ensure_desktop_exe_launchable(desktop_dir: Path, packaged_executable: Optio# Only the exe's OWN output dir is purged (a staging dir), never the live# release/ tree that still holds the last working app._purge_electron_build_cache(desktop_dir, release_dir=packaged_executable.parent.parent)- try:+ with contextlib.suppress(OSError):_desktop_stamp_path().unlink()- except OSError:- passrestored = _rollback_desktop_from_backup(packaged_executable)if restored is not None:@@ -562,10 +561,8 @@ def _redownload_electron_dist(project_root: Path, env: dict, *, mirror: Optionalreturn Falseshutil.rmtree(electron_dir / "dist", ignore_errors=True)- try:+ with contextlib.suppress(OSError):(electron_dir / "path.txt").unlink()- except OSError:- passdl_env = with_hermes_node_path(env)if mirror:diff --git a/hermes_cli/main_tui_launch.py b/hermes_cli/main_tui_launch.pyindex 5f62e521524..94476eb6ddf 100644--- a/hermes_cli/main_tui_launch.py+++ b/hermes_cli/main_tui_launch.py@@ -8,6 +8,7 @@ avoids an import cycle)."""import logging+import contextlibimport jsonimport osimport shutil@@ -767,10 +768,8 @@ def _launch_tui(if code in {0, 130}:_print_tui_exit_summary(resume_session_id, active_session_file)finally:- try:+ with contextlib.suppress(OSError):os.unlink(active_session_file)- except OSError:- passif wt_info:try:from cli import _cleanup_worktree