Propagate parse errors in stream_response instead of silently dropping them

Previously, if serde_json::from_str failed on a streamed line, the
line was silently discarded and the caller had no indication that data
was lost. Now parse errors are yielded as OllamaError::ResponseParseError
so consumers can detect and handle unexpected API responses.

Empty lines from LinesCodec are skipped to avoid spurious parse errors
on blank input between chunks.
This commit is contained in:
2026-01-30 19:28:02 +00:00
parent 098dc4426f
commit b70cc1a62d

View File

@@ -104,8 +104,9 @@ impl OllamaClient {
match line_result { match line_result {
Ok(line_content) => { Ok(line_content) => {
debug!(chunk = line_content, "ollama response chunk"); debug!(chunk = line_content, "ollama response chunk");
if let Ok(parsed) = serde_json::from_str::<T>(&line_content) { if !line_content.is_empty() {
yield Ok(parsed); yield serde_json::from_str::<T>(&line_content)
.map_err(OllamaError::from);
} }
} }
Err(e) => yield Err(OllamaError::from(e)), Err(e) => yield Err(OllamaError::from(e)),