Skip to content

Commit be2ed09

Browse files
committed
raise_if_dead(fix[FileNotFoundError]): Catch FileNotFoundError for invalid tmux_bin
why: subprocess.check_call raises FileNotFoundError when tmux_bin points to a nonexistent path, leaking a raw exception instead of TmuxCommandNotFound. what: - Wrap subprocess.check_call in try/except FileNotFoundError - Add test_tmux_bin_invalid_path_raise_if_dead test case
1 parent c4bf7d0 commit be2ed09

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

src/libtmux/server.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,10 @@ def raise_if_dead(self) -> None:
236236
if self.config_file:
237237
cmd_args.insert(0, f"-f{self.config_file}")
238238

239-
subprocess.check_call([resolved, *cmd_args])
239+
try:
240+
subprocess.check_call([resolved, *cmd_args])
241+
except FileNotFoundError:
242+
raise exc.TmuxCommandNotFound from None
240243

241244
#
242245
# Command

tests/test_server.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,3 +441,12 @@ def test_tmux_bin_invalid_path() -> None:
441441
s = Server(tmux_bin="/nonexistent/tmux")
442442
with pytest.raises(exc.TmuxCommandNotFound):
443443
s.cmd("list-sessions")
444+
445+
446+
def test_tmux_bin_invalid_path_raise_if_dead() -> None:
447+
"""Invalid tmux_bin raises TmuxCommandNotFound in raise_if_dead()."""
448+
from libtmux import exc
449+
450+
s = Server(tmux_bin="/nonexistent/tmux")
451+
with pytest.raises(exc.TmuxCommandNotFound):
452+
s.raise_if_dead()

0 commit comments

Comments
 (0)