Hmbown/CodeWhale · error
Failed to parse Anthropic SSE event: {e}
Error message
Failed to parse Anthropic SSE event: {e} What it means
In the Anthropic SSE stream handler, convert_anthropic_sse_data failing to parse an event's data payload yields Err("Failed to parse Anthropic SSE event: {e}") into the stream, terminating it. This fires when the upstream returns malformed or unexpected JSON on the SSE channel (proxy truncation, protocol drift, non-event body on a 200 stream) — the stream surfaces it as a normal error result for the turn rather than panicking.
Source
Thrown at crates/tui/src/client/anthropic.rs:374
};
match convert_anthropic_sse_data(data) {
Some(Ok(StreamEvent::Error { error })) => {
let (error_type, message) = anthropic_error_fields(&error);
yield Err(anyhow::anyhow!(
"Anthropic stream error ({error_type}): {message}"
));
return;
}
Some(Ok(event)) => {
let is_stop = matches!(event, StreamEvent::MessageStop);
yield Ok(event);
if is_stop {
return;
}
}
Some(Err(e)) => {
logging::warn(format!("Failed to parse Anthropic SSE event: {e}"));
}
None => {}
}
}
if ended {
break;
}
}
};
Ok(Box::pin(stream))
}
/// Handle a non-streaming Messages API request.
pub(super) async fn handle_anthropic_message(
&self,
prepared: &super::PreparedOutboundRequest,View on GitHub (pinned to 0c42157ee5)
Solutions
- Retry the request; transient proxy truncation is the most common cause
- Capture the raw SSE body (debug logging) if the error repeats to check for API protocol changes
- Confirm no auth/error HTML page is being streamed in place of SSE events
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at crates/tui/src/client/anthropic.rs:374 when the library encounters an invalid state.
Common situations: See trigger scenarios.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
AI-assisted analysis of Hmbown/CodeWhale@0c42157ee5 (2026-08-20).
Data as JSON: /api/errors/f676468b41d9f3e2.
Report an issue: GitHub.