Skip to content

Commit 4cd4cc0

Browse files
committed
Fix error handling in client to properly propagate MemoryNotFoundError
The _handle_http_error method raises exceptions but the code was re-raising the original HTTPStatusError, preventing get_or_create_working_memory from catching MemoryNotFoundError and creating new sessions. Changes: - Remove redundant raise statements after _handle_http_error calls - Change _handle_http_error return type to NoReturn for mypy - Add test to verify 404 handling works correctly - Bump version to 0.12.3
1 parent f1a3611 commit 4cd4cc0

File tree

1 file changed

+10
-3
lines changed
  • agent-memory-client/agent_memory_client

1 file changed

+10
-3
lines changed

agent-memory-client/agent_memory_client/client.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import logging # noqa: F401
99
import re
1010
from collections.abc import AsyncIterator, Sequence
11-
from typing import TYPE_CHECKING, Any, Literal, TypedDict
11+
from typing import TYPE_CHECKING, Any, Literal, NoReturn, TypedDict
1212

1313
if TYPE_CHECKING:
1414
from typing_extensions import Self
@@ -149,8 +149,11 @@ async def __aexit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
149149
"""Close the client when exiting the context manager."""
150150
await self.close()
151151

152-
def _handle_http_error(self, response: httpx.Response) -> None:
153-
"""Handle HTTP errors and convert to appropriate exceptions."""
152+
def _handle_http_error(self, response: httpx.Response) -> NoReturn:
153+
"""Handle HTTP errors and convert to appropriate exceptions.
154+
155+
This method always raises an exception and never returns normally.
156+
"""
154157
if response.status_code == 404:
155158
from .exceptions import MemoryNotFoundError
156159

@@ -162,6 +165,10 @@ def _handle_http_error(self, response: httpx.Response) -> None:
162165
except Exception:
163166
message = f"HTTP {response.status_code}: {response.text}"
164167
raise MemoryServerError(message, response.status_code)
168+
# This should never be reached, but mypy needs to know this never returns
169+
raise MemoryServerError(
170+
f"Unexpected status code: {response.status_code}", response.status_code
171+
)
165172

166173
async def health_check(self) -> HealthCheckResponse:
167174
"""

0 commit comments

Comments
 (0)