From 848f35f5dff94963d45dadcf891bcf6776c0eb2b Mon Sep 17 00:00:00 2001 From: kigland Date: Fri, 6 Mar 2026 23:05:02 +0800 Subject: [PATCH 1/2] fix: replace bare except handlers with specific exception types --- examples/foundational/39-mcp-stdio.py | 2 +- examples/foundational/39c-multiple-mcp.py | 2 +- src/pipecat/adapters/services/bedrock_adapter.py | 2 +- src/pipecat/serializers/telnyx.py | 2 +- src/pipecat/serializers/twilio.py | 2 +- src/pipecat/services/aws/llm.py | 2 +- src/pipecat/services/mcp_service.py | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/foundational/39-mcp-stdio.py b/examples/foundational/39-mcp-stdio.py index 2daf21626..51a15d68c 100644 --- a/examples/foundational/39-mcp-stdio.py +++ b/examples/foundational/39-mcp-stdio.py @@ -70,7 +70,7 @@ class UrlToImageProcessor(FrameProcessor): return data["artObject"]["webImage"]["url"] if "artworks" in data and len(data["artworks"]): return data["artworks"][0]["webImage"]["url"] - except: + except (json.JSONDecodeError, KeyError, TypeError): pass return None diff --git a/examples/foundational/39c-multiple-mcp.py b/examples/foundational/39c-multiple-mcp.py index 5f662cdb8..3349e04e6 100644 --- a/examples/foundational/39c-multiple-mcp.py +++ b/examples/foundational/39c-multiple-mcp.py @@ -72,7 +72,7 @@ class UrlToImageProcessor(FrameProcessor): return data["artObject"]["webImage"]["url"] if "artworks" in data and len(data["artworks"]): return data["artworks"][0]["webImage"]["url"] - except: + except (json.JSONDecodeError, KeyError, TypeError): pass async def run_image_process(self, image_url: str): diff --git a/src/pipecat/adapters/services/bedrock_adapter.py b/src/pipecat/adapters/services/bedrock_adapter.py index ccbbe5e2e..8fd474cb6 100644 --- a/src/pipecat/adapters/services/bedrock_adapter.py +++ b/src/pipecat/adapters/services/bedrock_adapter.py @@ -209,7 +209,7 @@ class AWSBedrockLLMAdapter(BaseLLMAdapter[AWSBedrockLLMInvocationParams]): tool_result_content = [{"json": content_json}] else: tool_result_content = [{"text": message["content"]}] - except: + except (json.JSONDecodeError, ValueError): tool_result_content = [{"text": message["content"]}] return { diff --git a/src/pipecat/serializers/telnyx.py b/src/pipecat/serializers/telnyx.py index 769244f93..1c0405ade 100644 --- a/src/pipecat/serializers/telnyx.py +++ b/src/pipecat/serializers/telnyx.py @@ -198,7 +198,7 @@ class TelnyxFrameSerializer(FrameSerializer): f"Telnyx call {call_control_id} was already terminated" ) return - except: + except Exception: pass # Fall through to log the raw error # Log other 422 errors diff --git a/src/pipecat/serializers/twilio.py b/src/pipecat/serializers/twilio.py index 72fec4f28..bf92a9043 100644 --- a/src/pipecat/serializers/twilio.py +++ b/src/pipecat/serializers/twilio.py @@ -212,7 +212,7 @@ class TwilioFrameSerializer(FrameSerializer): if error_data.get("code") == 20404: logger.debug(f"Twilio call {call_sid} was already terminated") return - except: + except Exception: pass # Fall through to log the raw error # Log other 404 errors diff --git a/src/pipecat/services/aws/llm.py b/src/pipecat/services/aws/llm.py index e465ae460..8f614cf8f 100644 --- a/src/pipecat/services/aws/llm.py +++ b/src/pipecat/services/aws/llm.py @@ -369,7 +369,7 @@ class AWSBedrockLLMContext(OpenAILLMContext): tool_result_content = [{"json": content_json}] else: tool_result_content = [{"text": message["content"]}] - except: + except (json.JSONDecodeError, ValueError): tool_result_content = [{"text": message["content"]}] return { diff --git a/src/pipecat/services/mcp_service.py b/src/pipecat/services/mcp_service.py index 936e210d2..302185719 100644 --- a/src/pipecat/services/mcp_service.py +++ b/src/pipecat/services/mcp_service.py @@ -298,7 +298,7 @@ class MCPClient(BaseObject): try: logger.debug(f"Found {len(available_tools)} available tools") - except: + except Exception: pass for tool in available_tools.tools: From 57f0b6d75bb9715167eaea15900786808eacb89f Mon Sep 17 00:00:00 2001 From: kigland Date: Sun, 8 Mar 2026 12:28:03 +0800 Subject: [PATCH 2/2] fix: address review feedback on exception handling - mcp_service.py: remove unnecessary try/except around debug log, use len(available_tools.tools) to match actual iteration target - bedrock_adapter.py, aws/llm.py: add AttributeError to except tuple to handle None content (previously caught by bare except) --- src/pipecat/adapters/services/bedrock_adapter.py | 2 +- src/pipecat/services/aws/llm.py | 2 +- src/pipecat/services/mcp_service.py | 5 +---- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/pipecat/adapters/services/bedrock_adapter.py b/src/pipecat/adapters/services/bedrock_adapter.py index 8fd474cb6..d63c5cf0f 100644 --- a/src/pipecat/adapters/services/bedrock_adapter.py +++ b/src/pipecat/adapters/services/bedrock_adapter.py @@ -209,7 +209,7 @@ class AWSBedrockLLMAdapter(BaseLLMAdapter[AWSBedrockLLMInvocationParams]): tool_result_content = [{"json": content_json}] else: tool_result_content = [{"text": message["content"]}] - except (json.JSONDecodeError, ValueError): + except (json.JSONDecodeError, ValueError, AttributeError): tool_result_content = [{"text": message["content"]}] return { diff --git a/src/pipecat/services/aws/llm.py b/src/pipecat/services/aws/llm.py index 8f614cf8f..ea8a76b8f 100644 --- a/src/pipecat/services/aws/llm.py +++ b/src/pipecat/services/aws/llm.py @@ -369,7 +369,7 @@ class AWSBedrockLLMContext(OpenAILLMContext): tool_result_content = [{"json": content_json}] else: tool_result_content = [{"text": message["content"]}] - except (json.JSONDecodeError, ValueError): + except (json.JSONDecodeError, ValueError, AttributeError): tool_result_content = [{"text": message["content"]}] return { diff --git a/src/pipecat/services/mcp_service.py b/src/pipecat/services/mcp_service.py index 302185719..d4f0807b8 100644 --- a/src/pipecat/services/mcp_service.py +++ b/src/pipecat/services/mcp_service.py @@ -296,10 +296,7 @@ class MCPClient(BaseObject): available_tools = await session.list_tools() tool_schemas: List[FunctionSchema] = [] - try: - logger.debug(f"Found {len(available_tools)} available tools") - except Exception: - pass + logger.debug(f"Found {len(available_tools.tools)} available tools") for tool in available_tools.tools: tool_name = tool.name