continuedev/continue · error · Error
Error parsing Ollama response: ${e} ${chunk}
Error message
Error parsing Ollama response: ${e} ${chunk} What it means
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.
Source
Thrown at core/llm/llms/Ollama.ts:456
for await (const value of streamResponse(response)) {
// Append the received chunk to the buffer
buffer += value;
// Split the buffer into individual JSON chunks
const chunks = buffer.split("\n");
buffer = chunks.pop() ?? "";
for (let i = 0; i < chunks.length; i++) {
const chunk = chunks[i];
if (chunk.trim() !== "") {
try {
const j = JSON.parse(chunk) as OllamaRawResponse;
if ("error" in j) {
throw new Error(j.error);
}
j.response ??= "";
yield j.response;
} catch (e) {
throw new Error(`Error parsing Ollama response: ${e} ${chunk}`);
}
}
}
}
}
/**
* Reorder messages so that system messages never appear directly after tool
* messages. Some Ollama models (Mistral, Ministral) reject the sequence
* `tool → system` with "Unexpected role 'system' after role 'tool'".
* This moves such system messages to just before the preceding
* assistant+tool block.
*/
private _reorderMessagesForToolCompat(
messages: OllamaChatMessage[],
): OllamaChatMessage[] {
const result: OllamaChatMessage[] = [...messages];
View on GitHub (pinned to 5522c6f44c)
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
Defensive patterns
Strategy: try-catch
Validate before calling
null
Type guard
function unwrapOllamaParseError(e: unknown): string | null {
const m = e instanceof Error ? e.message.match(/Error parsing Ollama response: (.*)/)?.[1] : null;
return m ?? null; // inner cause text
} Try / catch
try { for await (const c of llm.streamComplete(prompt, signal)) yield c; }
catch (e) { const cause = unwrapOllamaParseError(e); if (cause?.includes('not found')) ollamaPull(); else throw e; } Prevention
- Treat 'Error parsing Ollama response' as a wrapper — always decode the inner text
- Keep Ollama and the extension on current versions
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- j.error
- res.error
- Response body is null
- MCP Connection ${serverId} not found
- Error getting prompt: MCP Connection ${serverName} not found
AI-assisted analysis of continuedev/continue@5522c6f44c (2026-08-27).
Data as JSON: /api/errors/29cc6fb7ef076872.
Report an issue: GitHub.