gitbutlerapp/gitbutler · error
Invalid response: " + JSON.stringify(result)
Error message
Invalid response: " + JSON.stringify(result)
What it means
OllamaClient.chat() validates the Ollama /api/chat response with the isOllamaChatResponse type guard; a response that does not match the expected shape (message, etc.) throws this error with the JSON-serialized payload. It protects callers from malformed or unexpected server output.
Solutions
- Inspect the JSON in the error message to see what Ollama actually returned.
- Update or align the Ollama server version with the schema this client expects.
- Verify the Ollama host URL points at the correct /api endpoint.
- Check Ollama server logs for model load failures.
Example fix
// before
const client = new OllamaClient('http://localhost:8080'); // proxy returning error JSON
// after
const client = new OllamaClient('http://localhost:11434'); Defensive patterns
Strategy: type-guard
Validate before calling
const raw = await fetch(ollamaHost + '/api/tags');
if (!raw.ok) throw new Error('Ollama host not reachable/healthy'); Type guard
function isOllamaChatResponse(r: unknown): r is OllamaChatResponse {
return typeof r === 'object' && r !== null && 'message' in r && typeof (r as any).message?.content === 'string';
} Try / catch
try {
const resp = await client.chat(params);
// use resp
} catch (e) {
if (e.message.startsWith('Invalid response:')) {
const actual = e.message.slice('Invalid response:'.length);
// log actual payload; check for Ollama version/schema drift or { error } object
} else {
throw e;
}
} Prevention
- Pin/verify the Ollama server version against the client's expected schema.
- Point the client at the correct Ollama port (11434), not a proxy.
- Log unexpected payloads to detect upstream schema changes early.
When it happens
Trigger: Ollama returns a 200 response whose body lacks the expected chat response fields — e.g. an { error: ... } object, a proxy/auth HTML page, or a schema change in a new Ollama version.
Common situations: Outdated or newer Ollama version with changed response schema; response intercepted by a proxy or auth portal; pointing the Ollama host at the wrong port/path so an error JSON is returned; model failed to load and Ollama returned an error object with 200.
Related errors
- Ollama endpoint must use host:port format
- Aborting due to empty branch name
- Aborting due to empty
- API returned version
- At least one review number is required
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/bb5a153b1f2ebc93.
Report an issue: GitHub.
Appendix: source
Thrown at apps/desktop/src/lib/ai/ollamaClient.ts:84
* Sends a chat message to the LLM model and returns the response.
*
* @param messages - An array of LLMChatMessage objects representing the chat messages.
* @param options - Optional LLMRequestOptions object for specifying additional options.
* @returns A Promise that resolves to an LLMResponse object representing the response from the LLM model.
*/
private async chat(
messages: Prompt,
options?: OllamaRequestOptions,
): Promise<OllamaChatResponse> {
const result = await this.ollama.chat({
model: this.modelName,
messages,
stream: false,
options,
});
if (!isOllamaChatResponse(result)) {
throw new Error("Invalid response: " + JSON.stringify(result));
}
return result;
}
}
View on GitHub (pinned to 58e5313667)