Skip to content

Conversation

@h3xxit
Copy link
Member

@h3xxit h3xxit commented Aug 27, 2025

Summary by cubic

Fix JSON parsing in the HTTP protocol when servers send invalid JSON with Content-Type: application/json. We now catch parse errors, log them, and fall back to returning the raw text to avoid failing tool calls.

  • Bug Fixes

    • If response.json() fails under application/json, log an error and return response.text() to keep the call running.
  • Dependencies

    • Bump utcp-http to 1.0.3.

@h3xxit h3xxit merged commit 0f2af7e into main Aug 27, 2025
25 checks passed
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 2 files

React with 👍 or 👎 to teach cubic. You can also tag @cubic-dev-ai to give feedback, ask questions, or re-run the review.

return await response.json()
try:
return await response.json()
except Exception:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overly broad exception handler hides unexpected errors; catch specific JSON parsing/decode exceptions instead for safer error handling.

Prompt for AI agents
Address the following comment on plugins/communication_protocols/http/src/utcp_http/http_communication_protocol.py at line 318:

<comment>Overly broad exception handler hides unexpected errors; catch specific JSON parsing/decode exceptions instead for safer error handling.</comment>

<file context>
@@ -313,7 +313,11 @@ async def call_tool(self, caller, tool_name: str, tool_args: Dict[str, Any], too
-                        return await response.json()
+                        try:
+                            return await response.json()
+                        except Exception:
+                            logger.error(f&quot;Error parsing JSON response from tool &#39;{tool_name}&#39; on call template &#39;{tool_call_template.name}&#39;, even though Content-Type was application/json&quot;)
+                            return await response.text()
</file context>
Suggested change
except Exception:
except (json.JSONDecodeError, UnicodeDecodeError):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants