fix(core): unwrap ExceptionGroup in OAuth stream generator (#9346)
Fixes Datadog issue 5efbb1d4-eec5-11f0-8f8e-da7ad0900000 Add ExceptionGroup unwrapping in OAuth stream exception handler. The bug was caused by ExceptionGroup not being caught by the general `except Exception` handler, since ExceptionGroup is a subclass of BaseException, not Exception. This caused TaskGroup errors to escape as unhandled ExceptionGroups in Datadog. The fix adds an explicit ExceptionGroup handler before the general Exception handler, following the same unwrapping pattern used in other parts of the codebase (mcp_tool_executor.py, base_client.py). 🐾 Generated with [Letta Code](https://letta.com) Co-authored-by: Letta <noreply@letta.com>
This commit is contained in:
@@ -742,6 +742,13 @@ async def connect_mcp_server(
|
||||
async for event in server.mcp_manager.handle_oauth_flow(request=request, actor=actor, http_request=http_request):
|
||||
yield event
|
||||
return
|
||||
except ExceptionGroup as eg:
|
||||
# Handle ExceptionGroup wrapping (Python 3.11+ async TaskGroup can wrap exceptions)
|
||||
# Unwrap and handle the first exception in the group
|
||||
exception_to_handle = eg.exceptions[0] if eg.exceptions else eg
|
||||
detailed_error = drill_down_exception(exception_to_handle)
|
||||
logger.error(f"Error in OAuth stream (ExceptionGroup):\n{detailed_error}")
|
||||
yield oauth_stream_event(OauthStreamEvent.ERROR, message=f"Internal error: {detailed_error}")
|
||||
except Exception as e:
|
||||
detailed_error = drill_down_exception(e)
|
||||
logger.error(f"Error in OAuth stream:\n{detailed_error}")
|
||||
|
||||
Reference in New Issue
Block a user