mirror of
https://github.com/headroomlabs-ai/headroom.git
synced 2026-11-22 13:29:19 +08:00
fix(cli): treat a Click "Error:" line as the proxy startup error
The excerpt regex knew only ERROR/CRITICAL/Traceback, so the CLI's own
"Error: ..." lines (click.ClickException) were not picked as the cause. A line
starting with "Error: " now counts. Tests cover a Click error line among INFO
output and one followed by 192 KiB of whitespace, which 062cf011 reported as
"(no log output)".
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
409fee89a9
commit
92b1bd08ca
@@ -712,7 +712,11 @@ def _get_proxy_stdio_log_path(port: int | None = None) -> Path:
|
||||
# A proxy that dies during startup logs its shutdown summary after the error,
|
||||
# so the end of the log is the summary box, not the cause. Quote from the first
|
||||
# error-looking line instead.
|
||||
_PROXY_STARTUP_ERROR_RE = re.compile(r"\b(?:ERROR|CRITICAL)\b|Traceback \(most recent call last\)")
|
||||
# Click's own failures (``click.ClickException``) print ``Error: ...`` at the
|
||||
# start of a line.
|
||||
_PROXY_STARTUP_ERROR_RE = re.compile(
|
||||
r"\b(?:ERROR|CRITICAL)\b|Traceback \(most recent call last\)|^Error: ", re.MULTILINE
|
||||
)
|
||||
_PROXY_STARTUP_EXCERPT_CHARS = 500
|
||||
# Never read a runaway log whole: look at most at the first and the last 64 KiB
|
||||
# of this run's output. The error usually comes early, before the shutdown
|
||||
|
||||
@@ -318,6 +318,29 @@ class TestCLIWrapProxyTimeout:
|
||||
|
||||
assert excerpt.endswith("INFO last startup line")
|
||||
|
||||
def test_startup_excerpt_quotes_click_error_before_a_blank_tail(self, tmp_path):
|
||||
"""A Click ``Error:`` line followed by a whitespace-only tail is quoted,
|
||||
not reported as "(no log output)"."""
|
||||
stdio_log = tmp_path / "proxy-stdio-8787.log"
|
||||
stdio_log.write_text("Error: address already in use\n" + " " * (192 * 1024))
|
||||
|
||||
excerpt = wrap_mod._proxy_startup_failure_excerpt(stdio_log, 0)
|
||||
|
||||
assert excerpt == "Error: address already in use"
|
||||
|
||||
def test_startup_excerpt_starts_at_a_click_style_error_line(self, tmp_path):
|
||||
stdio_log = tmp_path / "proxy-stdio-8787.log"
|
||||
stdio_log.write_text(
|
||||
"INFO starting\nINFO loading config\n"
|
||||
"Error: Port 8787 on 127.0.0.1 is already in use by another process.\n"
|
||||
"INFO shutdown summary\n"
|
||||
)
|
||||
|
||||
excerpt = wrap_mod._proxy_startup_failure_excerpt(stdio_log, 0)
|
||||
|
||||
assert excerpt.startswith("Error: Port 8787 on 127.0.0.1 is already in use")
|
||||
assert "INFO starting" not in excerpt
|
||||
|
||||
def test_timeout_error_names_configured_timeout_and_env_var(self, monkeypatch, tmp_path):
|
||||
fake_proc = _FakeProxyProcess()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user