fix: propagate LinesCodecError in parse_sse_event (#8) #13

Merged
andreban merged 1 commits from fix/propagate-sse-lines-codec-error into main 2026-10-26 18:44:14 +00:00
Owner

Fixes #8

Summary

  • GeminiClient::parse_sse_event now propagates tokio_util::codec::LinesCodecError as Some(Err(Error::EventSourceError(err))) instead of converting it to None with .ok()?.
  • Mid-stream transport errors (connection resets, timeouts) and truncated events at EOF (where tokio-util's default decode_eof returns an I/O error on unparsed remaining bytes) are now surfaced to downstream callers rather than silently ending the stream as if generation completed normally.
  • parse_sse_event continues to return None when a valid event has no data (event.data: None), correctly ignoring empty keep-alive frames.

Testing

  • Added unit test parse_sse_event_propagates_lines_codec_error verifying LinesCodecError::Io is mapped to Error::EventSourceError.
  • Added unit test parse_sse_event_returns_none_when_data_is_none verifying keep-alive frames are skipped.
  • Added integration test stream_generate_content_yields_error_on_truncated_sse verifying that an SSE stream truncated before EOF yields Error::EventSourceError.
  • cargo test and cargo clippy pass cleanly.
Fixes #8 ## Summary - `GeminiClient::parse_sse_event` now propagates `tokio_util::codec::LinesCodecError` as `Some(Err(Error::EventSourceError(err)))` instead of converting it to `None` with `.ok()?`. - Mid-stream transport errors (connection resets, timeouts) and truncated events at EOF (where tokio-util's default `decode_eof` returns an I/O error on unparsed remaining bytes) are now surfaced to downstream callers rather than silently ending the stream as if generation completed normally. - `parse_sse_event` continues to return `None` when a valid event has no data (`event.data: None`), correctly ignoring empty keep-alive frames. ## Testing - Added unit test `parse_sse_event_propagates_lines_codec_error` verifying `LinesCodecError::Io` is mapped to `Error::EventSourceError`. - Added unit test `parse_sse_event_returns_none_when_data_is_none` verifying keep-alive frames are skipped. - Added integration test `stream_generate_content_yields_error_on_truncated_sse` verifying that an SSE stream truncated before EOF yields `Error::EventSourceError`. - `cargo test` and `cargo clippy` pass cleanly.
andreban added 1 commit 2026-10-26 18:43:35 +00:00
fix: propagate LinesCodecError in parse_sse_event (#8)
Some checks failed
Rust / build (pull_request) Failing after 8m5s
20f7a4a34c
andreban merged commit f9e74ee171 into main 2026-10-26 18:44:14 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: andreban/gemini-rs#13