The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: failed initialize keeps the LSP error type instead of raising TypeError (review follow-up)
teknium181faca2f1c0f
diff --git a/agent/lsp/client.py b/agent/lsp/client.pyindex 360c063b12b..8d268b41eeb 100644--- a/agent/lsp/client.py+++ b/agent/lsp/client.py@@ -234,9 +234,12 @@ class LSPClient:# CancelledError is a BaseException on supported Python versions, and cleanup# must outlive that cancellation or the spawned server escapes all tracking.await asyncio.shield(self._cleanup_process())+ # Attach the details to the ORIGINAL exception rather than re-instantiating its+ # type: LSPRequestError's ctor is (code, message, data), so ``type(e)(text)``+ # would surface as a TypeError instead of the LSP error the caller logs.details = self.failure_details()if details and isinstance(e, Exception):- raise type(e)(f"{e} ({details})") from e+ e.args = (f"{e} ({details})",)raiseasync def _spawn(self) -> None:diff --git a/tests/agent/lsp/_mock_lsp_server.py b/tests/agent/lsp/_mock_lsp_server.pyindex 67b1d9a5a92..d00e3121173 100644--- a/tests/agent/lsp/_mock_lsp_server.py+++ b/tests/agent/lsp/_mock_lsp_server.py@@ -114,6 +114,12 @@ def main():return 0if "id" in msg and msg.get("method") == "initialize":+ if script == "init_error":+ # A conformant JSON-RPC error to `initialize`, then exit: the client must+ # surface it as an LSPRequestError carrying the exit details.+ write_message({"jsonrpc": "2.0", "id": msg["id"],+ "error": {"code": -32602, "message": "bad init"}})+ return 0if script in {"slow", "slow_tree"}:time.sleep(1.0)write_message(diff --git a/tests/agent/lsp/test_client_e2e.py b/tests/agent/lsp/test_client_e2e.pyindex d1bab3b7eb8..5bd03b6849e 100644--- a/tests/agent/lsp/test_client_e2e.py+++ b/tests/agent/lsp/test_client_e2e.py@@ -15,7 +15,7 @@ from pathlib import Pathimport pytestfrom agent.lsp.client import LSPClient-from agent.lsp.protocol import LSPProtocolError+from agent.lsp.protocol import LSPProtocolError, LSPRequestErrorMOCK_SERVER = str(Path(__file__).parent / "_mock_lsp_server.py")@@ -96,6 +96,23 @@ async def test_aborted_start_reports_exit_status_and_stderr_tail(tmp_path: Path)await client.shutdown()+async def test_initialize_error_response_keeps_its_exception_type(tmp_path: Path):+ """A JSON-RPC error to ``initialize`` must surface as the LSPRequestError the server sent,+ with the exit details appended -- not as a TypeError from re-instantiating an exception+ class whose constructor is not ``(message)``."""+ client = _client(tmp_path, "init_error")++ with pytest.raises(LSPRequestError) as excinfo:+ await client.start()++ assert excinfo.value.code == -32602+ message = str(excinfo.value)+ assert "bad init" in message+ assert "server exited" in message+ await client.shutdown()++@pytest.mark.asyncioasync def test_failure_details_empty_for_live_server(tmp_path: Path):client = _client(tmp_path, "clean")