Skip to content

Commit 8d0ec49

Browse files
committed
fix(cli[stop]): Exit with code 1 on SessionNotFound
command_stop caught SessionNotFound, printed the error, but returned normally with exit code 0. This broke CI/scripting that relies on non-zero exit codes to detect failures. Now calls sys.exit(1).
1 parent 6f5ded6 commit 8d0ec49

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

src/tmuxp/cli/stop.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import argparse
66
import logging
77
import os
8+
import sys
89
import typing as t
910

1011
from libtmux.server import Server
@@ -122,7 +123,7 @@ def command_stop(
122123
raise exc.SessionNotFound(args.session_name)
123124
except TmuxpException as e:
124125
tmuxp_echo(colors.error(str(e)))
125-
return
126+
sys.exit(1)
126127

127128
session_name = session.name
128129

tests/cli/test_stop.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,15 @@ def test_stop_nonexistent_session(
6262
monkeypatch: pytest.MonkeyPatch,
6363
capsys: pytest.CaptureFixture[str],
6464
) -> None:
65-
"""Test stopping a session that doesn't exist shows error."""
65+
"""Test stopping a session that doesn't exist exits with code 1."""
6666
monkeypatch.delenv("TMUX", raising=False)
6767

6868
assert server.socket_name is not None
6969

70-
cli.cli(["stop", "nonexistent", "-L", server.socket_name])
70+
with pytest.raises(SystemExit) as exc_info:
71+
cli.cli(["stop", "nonexistent", "-L", server.socket_name])
7172

73+
assert exc_info.value.code == 1
7274
captured = capsys.readouterr()
7375
assert "Session not found" in captured.out
7476

0 commit comments

Comments
 (0)