zed-industries/zed · error
Error parsing JSON: {error:?}\n{line:?}
Error message
Error parsing JSON: {error:?}\n{line:?} What it means
A `data:` line in the SSE stream from stream_generateContent failed to deserialize into the expected response type. The offending line and parse error are included; causes are a schema drift between the server payload and the client structs, or a truncated/interleaved SSE line.
Source
Thrown at crates/opencode/src/opencode.rs:965
.method(Method::POST)
.uri(uri)
.header("Content-Type", "application/json")
.header("Authorization", format!("Bearer {api_key}"))
.extra_headers(extra_headers)
.body(AsyncBody::from(serde_json::to_string(&request)?))?;
let mut response = client.send(request).await?;
if response.status().is_success() {
let reader = BufReader::new(response.into_body());
Ok(reader
.lines()
.filter_map(|line| async move {
match line {
Ok(line) => {
if let Some(line) = line.strip_prefix("data: ") {
match serde_json::from_str(line) {
Ok(response) => Some(Ok(response)),
Err(error) => {
Some(Err(anyhow!("Error parsing JSON: {error:?}\n{line:?}")))
}
}
} else {
None
}
}
Err(error) => Some(Err(anyhow!(error))),
}
})
.boxed())
} else {
let mut text = String::new();
response.body_mut().read_to_string(&mut text).await?;
Err(anyhow!(
"error during streamGenerateContent via OpenCode, status code: {:?}, body: {}",
response.status(),
text
))View on GitHub (pinned to f4178619ac)
Solutions
- Log the failing line to determine whether the payload schema changed and update the deserialization structs
- If lines are truncated, check for proxy or buffering issues mangling the SSE stream
- Retry the request — occasional malformed chunks can be transient
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/opencode/src/opencode.rs:965 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of zed-industries/zed@f4178619ac (2026-08-20).
Data as JSON: /api/errors/dbe3f479f2994752.
Report an issue: GitHub.