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:
@@ -104,8 +104,9 @@ impl OllamaClient {
|
||||
match line_result {
|
||||
Ok(line_content) => {
|
||||
debug!(chunk = line_content, "ollama response chunk");
|
||||
if let Ok(parsed) = serde_json::from_str::<T>(&line_content) {
|
||||
yield Ok(parsed);
|
||||
if !line_content.is_empty() {
|
||||
yield serde_json::from_str::<T>(&line_content)
|
||||
.map_err(OllamaError::from);
|
||||
}
|
||||
}
|
||||
Err(e) => yield Err(OllamaError::from(e)),
|
||||
|
||||
Reference in New Issue
Block a user