Skip to content

Commit 44a4d8e

Browse files
Handle concatenated JSON responses in RPC parsing
Fix edge case where server returns multiple concatenated JSON objects due to HTTP connection issues. Extract and parse only the first object. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent cbd30bc commit 44a4d8e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/rpc.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,15 @@ pub(super) async fn send_rpcmsg(msg: String) -> Result<String, RPCError> {
12211221
Err(err) => return Err(RPCError::new(&err.to_string(), false)),
12221222
};
12231223

1224-
let rpc_reply: RPCReplyMsg = serde_json::from_str(body.as_str())
1224+
// Handle edge case where server returns multiple concatenated JSON objects
1225+
// This can happen due to HTTP connection issues - extract just the first object
1226+
let body_to_parse = if body.contains("}{") {
1227+
body.split("}{").next().map(|s| format!("{}}}", s)).unwrap_or(body.clone())
1228+
} else {
1229+
body.clone()
1230+
};
1231+
1232+
let rpc_reply: RPCReplyMsg = serde_json::from_str(body_to_parse.as_str())
12251233
.map_err(|e| RPCError::new(&format!("Failed to parse response: {} - body: {}", e, body), false))?;
12261234
let buf = BASE64.decode(rpc_reply.payload.as_str())
12271235
.map_err(|e| RPCError::new(&format!("Failed to decode payload: {}", e), false))?;

0 commit comments

Comments
 (0)