diff --git a/docsgpt/deploy/commands.py b/docsgpt/deploy/commands.py index 8b1503a6..0811134f 100644 --- a/docsgpt/deploy/commands.py +++ b/docsgpt/deploy/commands.py @@ -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: diff --git a/tests/deploy/test_doctor.py b/tests/deploy/test_doctor.py index b92104ce..3cc94dfd 100644 --- a/tests/deploy/test_doctor.py +++ b/tests/deploy/test_doctor.py @@ -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,