Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/sbx/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import re
import shlex
import shutil
import signal
import sqlite3
import subprocess
import sys
Expand Down Expand Up @@ -2214,6 +2215,9 @@ def main(argv: Sequence[str] | None = None) -> int:
return 2
try:
return args.func(args)
except KeyboardInterrupt:
# Shell convention: signal exits are 128 + signal number.
return 128 + signal.SIGINT
except ConfigError as exc:
print(f"sbx: {exc}", file=sys.stderr)
return 2
Expand Down
9 changes: 9 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1431,6 +1431,15 @@ def test_network_forward_accepts_explicit_name(monkeypatch: pytest.MonkeyPatch)
}


def test_network_forward_ctrl_c_returns_130(monkeypatch: pytest.MonkeyPatch) -> None:
def interrupted(vm_id: str, forward: tuple[str, int, int]) -> int:
raise KeyboardInterrupt

monkeypatch.setattr(cli.network, "_foreground_port_forward", interrupted)

assert cli.main(["network", "forward", "vm2", "3005"]) == 130


def test_network_commands_default_to_configured_name(
monkeypatch: pytest.MonkeyPatch,
tmp_path: Path,
Expand Down