fix: doctor reports a bad DOCSGPT_PORT instead of raising on it

_port_number was written so a hand-edited .env could not reach int() raw, and
then doctor did exactly that: a nonnumeric port ended the command with a
traceback rather than the message, in the one command whose job is to explain a
broken setup.
This commit is contained in:
Alex committed 2026-09-17 11:43:53 +01:00
1 parent 731baa7d31
commit bcf2707efa
2 files changed
+14 -1

No files matched your search

+3 -1
View File
@@ -862,7 +862,9 @@ def doctor(args, context: Optional[Context] = None) -> int:
_check_provider(env),
]
port = int(env.get("DOCSGPT_PORT") or stack.DEFAULT_PORT)
# The one command that exists to explain a broken setup must not fall over on one.
port = _port_number(env["DOCSGPT_PORT"], f"DOCSGPT_PORT in {env_path}") if env.get("DOCSGPT_PORT") \
else stack.DEFAULT_PORT
if _port_is_free(port):
checks.append(Check("port", "ok", f"{port} is free"))
else:
+11
View File
@@ -274,6 +274,17 @@ class TestDoctor:
assert "FAIL" in captured.out
assert "1 problem" in captured.err
def test_a_hand_edited_port_is_reported_not_raised(self, tmp_path, monkeypatch):
"""Doctor exists to explain a broken setup, so it must not traceback on one."""
self._only(
monkeypatch,
commands.Check("postgres", "ok", "fine"),
commands.Check("redis", "ok", "fine"),
)
(tmp_path / ".env").write_text("DOCSGPT_PORT=seven thousand\n", encoding="utf-8")
with pytest.raises(DeployError, match="not a port number"):
_run(["doctor", "--dir", str(tmp_path)], _context())
def test_it_says_which_settings_file_it_read(self, tmp_path, capsys, monkeypatch):
self._only(
monkeypatch,