|
| 1 | +import logging |
1 | 2 | from contextlib import AbstractAsyncContextManager
|
2 | 3 | from datetime import timedelta
|
3 | 4 | from typing import Any, Callable, Generic, TypeVar
|
@@ -273,19 +274,28 @@ async def _receive_loop(self) -> None:
|
273 | 274 | await self._incoming_message_stream_writer.send(responder)
|
274 | 275 |
|
275 | 276 | elif isinstance(message.root, JSONRPCNotification):
|
276 |
| - notification = self._receive_notification_type.model_validate( |
277 |
| - message.root.model_dump( |
278 |
| - by_alias=True, mode="json", exclude_none=True |
| 277 | + try: |
| 278 | + notification = self._receive_notification_type.model_validate( |
| 279 | + message.root.model_dump( |
| 280 | + by_alias=True, mode="json", exclude_none=True |
| 281 | + ) |
| 282 | + ) |
| 283 | + # Handle cancellation notifications |
| 284 | + if isinstance(notification.root, CancelledNotification): |
| 285 | + cancelled_id = notification.root.params.requestId |
| 286 | + if cancelled_id in self._in_flight: |
| 287 | + await self._in_flight[cancelled_id].cancel() |
| 288 | + else: |
| 289 | + await self._received_notification(notification) |
| 290 | + await self._incoming_message_stream_writer.send( |
| 291 | + notification |
| 292 | + ) |
| 293 | + except Exception as e: |
| 294 | + # For other validation errors, log and continue |
| 295 | + logging.warning( |
| 296 | + f"Failed to validate notification: {e}. " |
| 297 | + f"Message was: {message.root}" |
279 | 298 | )
|
280 |
| - ) |
281 |
| - # Handle cancellation notifications |
282 |
| - if isinstance(notification.root, CancelledNotification): |
283 |
| - cancelled_id = notification.root.params.requestId |
284 |
| - if cancelled_id in self._in_flight: |
285 |
| - await self._in_flight[cancelled_id].cancel() |
286 |
| - else: |
287 |
| - await self._received_notification(notification) |
288 |
| - await self._incoming_message_stream_writer.send(notification) |
289 | 299 | else: # Response or error
|
290 | 300 | stream = self._response_streams.pop(message.root.id, None)
|
291 | 301 | if stream:
|
|
0 commit comments