{"record":{"id":"29cc6fb7ef076872","repo":"continuedev/continue","slug":"error-parsing-ollama-response-e-chunk","errorCode":null,"errorMessage":"Error parsing Ollama response: ${e} ${chunk}","messagePattern":"Error parsing Ollama response: (.+?) (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"core/llm/llms/Ollama.ts","lineNumber":456,"sourceCode":"    for await (const value of streamResponse(response)) {\n      // Append the received chunk to the buffer\n      buffer += value;\n      // Split the buffer into individual JSON chunks\n      const chunks = buffer.split(\"\\n\");\n      buffer = chunks.pop() ?? \"\";\n\n      for (let i = 0; i < chunks.length; i++) {\n        const chunk = chunks[i];\n        if (chunk.trim() !== \"\") {\n          try {\n            const j = JSON.parse(chunk) as OllamaRawResponse;\n            if (\"error\" in j) {\n              throw new Error(j.error);\n            }\n            j.response ??= \"\";\n            yield j.response;\n          } catch (e) {\n            throw new Error(`Error parsing Ollama response: ${e} ${chunk}`);\n          }\n        }\n      }\n    }\n  }\n\n  /**\n   * Reorder messages so that system messages never appear directly after tool\n   * messages. Some Ollama models (Mistral, Ministral) reject the sequence\n   * `tool → system` with \"Unexpected role 'system' after role 'tool'\".\n   * This moves such system messages to just before the preceding\n   * assistant+tool block.\n   */\n  private _reorderMessagesForToolCompat(\n    messages: OllamaChatMessage[],\n  ): OllamaChatMessage[] {\n    const result: OllamaChatMessage[] = [...messages];\n","sourceCodeStart":438,"sourceCodeEnd":474,"githubUrl":"https://github.com/continuedev/continue/blob/5522c6f44ca0ac3528b37244818fbfa39b5af470/core/llm/llms/Ollama.ts#L438-L474","documentation":"Wrapper error from Ollama._streamComplete's catch block: any failure while parsing or handling a stream chunk — including the inline j.error throw — is rethrown as 'Error parsing Ollama response'. The original error and the offending chunk are embedded in the message, which commonly masks an Ollama-level error as a parse failure.","triggerScenarios":"A non-empty stream line that isn't valid JSON, or a valid JSON line containing an error field (which throws inside the try and gets re-wrapped here). Also triggered when the model's output contains malformed NDJSON due to crashes mid-stream.","commonSituations":"Ollama server killed mid-generation, proxy/load balancer truncating the stream, or the actual root cause being a model-not-found error re-wrapped by this catch.","solutions":["Read the embedded ${e} portion — if it says 'model not found' or similar, fix that underlying issue (ollama pull)","If the chunk looks truncated, check for proxies or timeouts between client and Ollama","Update Ollama to a version whose streaming format matches"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"null","typeGuard":"function unwrapOllamaParseError(e: unknown): string | null {\n  const m = e instanceof Error ? e.message.match(/Error parsing Ollama response: (.*)/)?.[1] : null;\n  return m ?? null; // inner cause text\n}","tryCatchPattern":"try { for await (const c of llm.streamComplete(prompt, signal)) yield c; }\ncatch (e) { const cause = unwrapOllamaParseError(e); if (cause?.includes('not found')) ollamaPull(); else throw e; }","preventionTips":["Treat 'Error parsing Ollama response' as a wrapper — always decode the inner text","Keep Ollama and the extension on current versions"],"tags":["ollama","streaming","json-parse","error-wrapping"],"backgroundTag":"llm-provider-stream-error","analyzedSha":"5522c6f44ca0ac3528b37244818fbfa39b5af470","analyzedAt":"2026-08-27T11:28:54.683Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}