| |
| """ |
| Simple Error Handling for MCPMark |
| ================================== |
| |
| Provides basic error standardization and retry logic. |
| """ |
|
|
| from typing import Optional |
|
|
|
|
| """Retryable error detection via minimal substring matching (lower-case).""" |
|
|
| |
| RETRYABLE_PATTERNS = { |
| "ratelimit", |
| |
| "agent execution failed", |
| "unavailable", |
| |
| "internal server error", |
| "network error", |
| "quota", |
| |
| |
| "account balance", |
| "mcp network error", |
| "state duplication error", |
| "thought_signature", |
| "overloaded." |
| } |
|
|
|
|
| def is_retryable_error(error: str) -> bool: |
| """Return True if the error string contains any retryable pattern.""" |
| error_lower = str(error or "").lower() |
| return any(pattern in error_lower for pattern in RETRYABLE_PATTERNS) |
|
|
|
|
| def standardize_error_message(error: str, mcp_service: Optional[str] = None) -> str: |
| """Standardize error messages for consistent reporting.""" |
| error_str = str(error).strip() |
|
|
| |
| if "timeout" in error_str.lower(): |
| base_msg = "Operation timed out" |
| elif ( |
| "connection refused" in error_str.lower() or "econnrefused" in error_str.lower() |
| ): |
| base_msg = "Connection refused" |
| elif "not found" in error_str.lower(): |
| base_msg = "Resource not found" |
| elif "already exists" in error_str.lower(): |
| base_msg = "Resource already exists" |
| else: |
| |
| return error_str |
|
|
| |
| if mcp_service: |
| return f"{mcp_service.title()} {base_msg}" |
|
|
| return base_msg |
|
|