Skip to content

Commit d280547

Browse files
committed
tmux_cmd(fix[FileNotFoundError]): Raise TmuxCommandNotFound for invalid tmux_bin
why: Invalid custom tmux_bin raised raw FileNotFoundError from subprocess instead of the domain-specific TmuxCommandNotFound, creating an inconsistent API surface. what: - Catch FileNotFoundError before generic Exception in tmux_cmd.__init__ - Re-raise as TmuxCommandNotFound from None - Update test_tmux_bin_invalid_path to expect TmuxCommandNotFound
1 parent a6a72df commit d280547

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

src/libtmux/common.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,8 @@ def __init__(self, *args: t.Any, tmux_bin: str | None = None) -> None:
276276
)
277277
stdout, stderr = self.process.communicate()
278278
returncode = self.process.returncode
279+
except FileNotFoundError:
280+
raise exc.TmuxCommandNotFound from None
279281
except Exception:
280282
logger.error( # noqa: TRY400
281283
"tmux subprocess failed",

tests/test_server.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,9 @@ def test_tmux_bin_custom_path() -> None:
432432

433433

434434
def test_tmux_bin_invalid_path() -> None:
435-
"""Invalid tmux_bin raises on command execution."""
435+
"""Invalid tmux_bin raises TmuxCommandNotFound."""
436+
from libtmux import exc
437+
436438
s = Server(tmux_bin="/nonexistent/tmux")
437-
with pytest.raises(FileNotFoundError):
439+
with pytest.raises(exc.TmuxCommandNotFound):
438440
s.cmd("list-sessions")

0 commit comments

Comments
 (0)