[PR #13007] api/client: handle non-json streaming errors #12777

Open
opened 2025-11-12 17:06:34 -06:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/13007
Author: @BruceMacD
Created: 11/8/2025
Status: 🔄 Open

Base: mainHead: brucemacd/invalid-char-i-err


📝 Commits (3)

  • 7f9dc9d api/client: handle non-json streaming errors
  • 63cc644 Update client_test.go
  • 14d7ed5 non-json response tests for client do

📊 Changes

2 files changed (+76 additions, -11 deletions)

View changed files

📝 api/client.go (+8 -1)
📝 api/client_test.go (+68 -10)

📄 Description

While processing the response stream during a chat or generation if an error is occurred it is parsed and returned to the user. The issue with the existing code is that this assumed the response would be valid JSON, which is not a safe assumption and caused cryptic error messages to be displayed due to parsing failures: invalid character 'i' looking for beginning of value.

This change updates the stream function to return the raw error string if it cant be parsed as JSON. This should help with debugging issues by making sure the actual error reaches the user.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama/pull/13007 **Author:** [@BruceMacD](https://github.com/BruceMacD) **Created:** 11/8/2025 **Status:** 🔄 Open **Base:** `main` ← **Head:** `brucemacd/invalid-char-i-err` --- ### 📝 Commits (3) - [`7f9dc9d`](https://github.com/ollama/ollama/commit/7f9dc9d7088b15423d0d2ff7cfe86f3cddf71ca0) api/client: handle non-json streaming errors - [`63cc644`](https://github.com/ollama/ollama/commit/63cc644f73b40a03c713d8538adc9386b4e51944) Update client_test.go - [`14d7ed5`](https://github.com/ollama/ollama/commit/14d7ed554ad3c639fcf331059d731c12e8f3a351) non-json response tests for client do ### 📊 Changes **2 files changed** (+76 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `api/client.go` (+8 -1) 📝 `api/client_test.go` (+68 -10) </details> ### 📄 Description While processing the response stream during a chat or generation if an error is occurred it is parsed and returned to the user. The issue with the existing code is that this assumed the response would be valid JSON, which is not a safe assumption and caused cryptic error messages to be displayed due to parsing failures: `invalid character 'i' looking for beginning of value`. This change updates the stream function to return the raw error string if it cant be parsed as JSON. This should help with debugging issues by making sure the actual error reaches the user. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the
pull-request
label 2025-11-12 17:06:34 -06:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama-ollama#12777
No description provided.