continuedev/continue · error · Error
Malformed JSON sent from server: ${json}
Error message
Malformed JSON sent from server: ${json} What it means
parseDataLine caught a JSON.parse failure on an SSE 'data:' line that wasn't already a streaming error, so the raw line is reported as malformed JSON from the server.
Source
Thrown at packages/fetch/src/stream.ts:107
console.error("Error in streamed response:", data.error);
throw new Error(`Error streaming response: ${data.error.message}`);
}
throw new Error(
`Error streaming response: ${JSON.stringify(data.error)}`,
);
}
return data;
} catch (e) {
// If the error was thrown by our error check, rethrow it
if (
e instanceof Error &&
e.message.startsWith("Error streaming response:")
) {
throw e;
}
// Otherwise it's a JSON parsing error
throw new Error(`Malformed JSON sent from server: ${json}`);
}
}
function parseSseLine(line: string): { done: boolean; data: any } {
if (line.startsWith("data:[DONE]") || line.startsWith("data: [DONE]")) {
return { done: true, data: undefined };
}
if (line.startsWith("data:")) {
return { done: false, data: parseDataLine(line) };
}
if (line.startsWith(": ping")) {
return { done: true, data: undefined };
}
return { done: false, data: undefined };
}
export async function* streamSse(response: Response): AsyncGenerator<any> {
let buffer = "";View on GitHub (pinned to 5522c6f44c)
Solutions
- Log the offending line to see what actually arrived (HTML? truncated JSON?)
- Retry — truncation is often transient
- Fix server/proxy to emit only valid JSON data lines
- Handle multi-line SSE 'data:' events per the SSE spec by joining consecutive data lines before parsing
Defensive patterns
Strategy: try-catch
Try / catch
catch (e) { if (/^Malformed JSON sent from server:/.test(e.message)) { console.error('raw line:', e.message.slice(30)); /* retry or switch endpoint */ } } Prevention
- Retry once — truncation is often transient
- Log the offending line to spot HTML/heartbeat injections
- Join consecutive SSE data: lines before parsing per the SSE spec
When it happens
Trigger: A 'data: ...' line whose payload isn't valid JSON — truncated by network issues, HTML error pages injected mid-stream, or multi-line data split incorrectly.
Common situations: Proxies injecting HTML, servers sending non-JSON heartbeats/comments as data, or chunk truncation from connection issues.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Malformed JSON sent from server: ${line}
- Error streaming response: ${data.error.message}
- Error streaming response: ${JSON.stringify(data.error)}
- Malformed JSON received from Bedrock: ${decoded}
- non-200 response body: ${await response.text()}
AI-assisted analysis of continuedev/continue@5522c6f44c (2026-08-27).
Data as JSON: /api/errors/c75cc54f9c098b6b.
Report an issue: GitHub.