{"record":{"id":"c75cc54f9c098b6b","repo":"continuedev/continue","slug":"malformed-json-sent-from-server-json","errorCode":null,"errorMessage":"Malformed JSON sent from server: ${json}","messagePattern":"Malformed JSON sent from server: (.+?)","errorType":"error_code","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/fetch/src/stream.ts","lineNumber":107,"sourceCode":"        console.error(\"Error in streamed response:\", data.error);\n        throw new Error(`Error streaming response: ${data.error.message}`);\n      }\n      throw new Error(\n        `Error streaming response: ${JSON.stringify(data.error)}`,\n      );\n    }\n\n    return data;\n  } catch (e) {\n    // If the error was thrown by our error check, rethrow it\n    if (\n      e instanceof Error &&\n      e.message.startsWith(\"Error streaming response:\")\n    ) {\n      throw e;\n    }\n    // Otherwise it's a JSON parsing error\n    throw new Error(`Malformed JSON sent from server: ${json}`);\n  }\n}\n\nfunction parseSseLine(line: string): { done: boolean; data: any } {\n  if (line.startsWith(\"data:[DONE]\") || line.startsWith(\"data: [DONE]\")) {\n    return { done: true, data: undefined };\n  }\n  if (line.startsWith(\"data:\")) {\n    return { done: false, data: parseDataLine(line) };\n  }\n  if (line.startsWith(\": ping\")) {\n    return { done: true, data: undefined };\n  }\n  return { done: false, data: undefined };\n}\n\nexport async function* streamSse(response: Response): AsyncGenerator<any> {\n  let buffer = \"\";","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/continuedev/continue/blob/5522c6f44ca0ac3528b37244818fbfa39b5af470/packages/fetch/src/stream.ts#L89-L125","documentation":"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.","triggerScenarios":"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.","commonSituations":"Proxies injecting HTML, servers sending non-JSON heartbeats/comments as data, or chunk truncation from connection issues.","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"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"catch (e) { if (/^Malformed JSON sent from server:/.test(e.message)) { console.error('raw line:', e.message.slice(30)); /* retry or switch endpoint */ } }","preventionTips":["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"],"tags":["fetch","streaming","sse","json","malformed-response"],"backgroundTag":"malformed-stream-json","analyzedSha":"5522c6f44ca0ac3528b37244818fbfa39b5af470","analyzedAt":"2026-08-27T11:28:54.683Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}