-
Notifications
You must be signed in to change notification settings - Fork 5
fix: proper error handling #114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 3.10 | ||
| 3.11 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,10 +3,10 @@ | |
| import os | ||
| import sys | ||
| import tempfile | ||
| import traceback | ||
| import uuid | ||
| from typing import Any, Dict, Optional | ||
|
|
||
| from httpx import HTTPStatusError | ||
| from mcp import ClientSession, StdioServerParameters, stdio_client | ||
| from mcp.types import JSONRPCResponse | ||
| from opentelemetry import trace | ||
|
|
@@ -329,35 +329,11 @@ async def _register(self) -> None: | |
| # We'll handle this after exiting the context managers | ||
| # We don't continue with registration here - we'll do it after the context managers | ||
|
|
||
| except BaseException as e: | ||
| # In Python 3.10, ExceptionGroup is in the 'exceptiongroup' module | ||
| # and asyncio.TaskGroup wraps exceptions in ExceptionGroup | ||
| if hasattr(e, "__context__") and e.__context__ is not None: | ||
| logger.error("Sub-exception details:") | ||
| except* Exception as eg: | ||
| for e in eg.exceptions: | ||
| logger.error( | ||
| "".join( | ||
| traceback.format_exception( | ||
| type(e.__context__), | ||
| e.__context__, | ||
| e.__context__.__traceback__, | ||
| ) | ||
| ) | ||
| ) | ||
| elif hasattr(e, "exceptions"): # For ExceptionGroup | ||
| for i, sub_exc in enumerate(e.exceptions): | ||
| logger.error(f"Sub-exception {i + 1}:") | ||
| logger.error( | ||
| "".join( | ||
| traceback.format_exception( | ||
| type(sub_exc), sub_exc, sub_exc.__traceback__ | ||
| ) | ||
| ) | ||
| ) | ||
| else: | ||
| # Log the full traceback of the exception itself | ||
| logger.error("Full traceback:") | ||
| logger.error( | ||
| "".join(traceback.format_exception(type(e), e, e.__traceback__)) | ||
| f"Unexpected error: {e}", | ||
| exc_info=True, | ||
| ) | ||
|
|
||
| # Now that we're outside the context managers, check if initialization succeeded | ||
|
|
@@ -395,8 +371,6 @@ async def _register(self) -> None: | |
| } | ||
| client_info["tools"].append(tool_info) | ||
|
|
||
| logger.info(client_info) | ||
|
|
||
| # Register with UiPath MCP Server | ||
| await self._uipath.api_client.request_async( | ||
| "POST", | ||
|
|
@@ -407,8 +381,10 @@ async def _register(self) -> None: | |
| logger.info("Registered MCP Server type successfully") | ||
| except Exception as e: | ||
| logger.error(f"Error during registration: {e}") | ||
| if e.status_code == 400: | ||
| logger.error(f"Error details: {e.response.text}") | ||
| if isinstance(e, HTTPStatusError): | ||
| logger.error( | ||
| f"HTTP error details: {e.response.text} status code: {e.response.status_code}" | ||
| ) | ||
|
|
||
|
Comment on lines
382
to
388
|
||
| raise UiPathMcpRuntimeError( | ||
| "REGISTRATION_ERROR", | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -143,15 +143,16 @@ async def _run_server(self, server_params: StdioServerParameters) -> None: | |||||||||||||||||
| # Cancel the consumer when we exit the loop | ||||||||||||||||||
| consumer_task.cancel() | ||||||||||||||||||
| try: | ||||||||||||||||||
| await consumer_task | ||||||||||||||||||
| except asyncio.CancelledError: | ||||||||||||||||||
| await asyncio.wait_for(consumer_task, timeout=2.0) | ||||||||||||||||||
| except (asyncio.CancelledError, asyncio.TimeoutError): | ||||||||||||||||||
| pass | ||||||||||||||||||
|
Comment on lines
+147
to
148
|
||||||||||||||||||
| except (asyncio.CancelledError, asyncio.TimeoutError): | |
| pass | |
| except asyncio.CancelledError: | |
| pass | |
| except asyncio.TimeoutError: | |
| logger.warning( | |
| f"Timeout occurred while shutting down consumer task for session {self._session_id}. Task may not have terminated cleanly." | |
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Removing this info-level log may reduce visibility into client configuration during troubleshooting; consider demoting it to
logger.debuginstead of dropping it entirely.