Skip to content

Commit 0617933

Browse files
committed
Server(refactor[errors]): Refine daemon detection and docstrings
why: Tighten the internal implementation and documentation for daemon-not-up states. what: - src/libtmux/server.py: In-line missing-socket marker and simplify _is_daemon_not_up_error logic. - src/libtmux/server.py: Compress _fetch_or_empty and _is_daemon_not_up_error docstrings for clarity.
1 parent 064de55 commit 0617933

1 file changed

Lines changed: 16 additions & 20 deletions

File tree

src/libtmux/server.py

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,16 @@
4848
logger = logging.getLogger(__name__)
4949

5050

51-
_MISSING_SOCKET_MARKER = "No such file or directory"
52-
53-
5451
def _is_daemon_not_up_error(stderr_text: str) -> bool:
55-
"""Return True for tmux errors that mean the server has not started."""
52+
"""Return True if the error indicates the tmux server is not running.
53+
54+
tmux signals this in two ways:
55+
1. "no server running" (socket exists but no daemon is listening)
56+
2. "error connecting to ... (No such file or directory)" (socket file is missing)
57+
"""
5658
return "no server running" in stderr_text or (
57-
"error connecting to" in stderr_text and _MISSING_SOCKET_MARKER in stderr_text
59+
"error connecting to" in stderr_text
60+
and "No such file or directory" in stderr_text
5861
)
5962

6063

@@ -63,25 +66,18 @@ def _fetch_or_empty(
6366
list_cmd: str,
6467
**kwargs: t.Any,
6568
) -> list[dict[str, t.Any]]:
66-
"""Wrap :func:`fetch_objs`: treat daemon-not-up stderr as empty.
67-
68-
tmux signals "no daemon" in two ways depending on socket state:
69-
``no server running on <socket>`` when the socket exists but no
70-
daemon is listening, or ``error connecting to <socket> (No such file
71-
or directory)`` when the socket file is missing entirely. Both are
72-
bootstrap signals — a fresh :class:`~libtmux.Server` can still be
73-
introspected via
74-
:attr:`Server.sessions`, :attr:`Server.windows`, etc. without
75-
first calling :meth:`Server.is_alive`. Other tmux errors, such as a
76-
permission failure on the socket, still propagate.
69+
"""Wrap :func:`fetch_objs`: treat a not-yet-started server as empty.
70+
71+
A fresh :class:`~libtmux.Server` can be introspected via
72+
:attr:`Server.sessions`, :attr:`Server.windows`, etc. before the
73+
daemon is up. Other tmux errors, such as socket permission
74+
failures, still propagate.
7775
"""
7876
try:
7977
return fetch_objs(server=server, list_cmd=list_cmd, **kwargs) # type: ignore[arg-type]
8078
except exc.LibTmuxException as e:
81-
if e.args:
82-
msg = str(e.args[0])
83-
if _is_daemon_not_up_error(msg):
84-
return []
79+
if e.args and _is_daemon_not_up_error(str(e.args[0])):
80+
return []
8581
raise
8682

8783

0 commit comments

Comments
 (0)