Hmbown/CodeWhale · error

{err}

Error message

{err}

What it means

A raw line could not be extracted from the SSE byte stream: super::take_sse_line returned Err and its detail is re-yielded verbatim at crates/tui/src/client/responses.rs:264. This guards the framing layer before any JSON parsing, so a failure means the stream itself is not well-formed SSE - an oversized line beyond the line buffer cap, invalid UTF-8, or CR/LF framing the parser rejects.

Source

Thrown at crates/tui/src/client/responses.rs:264

                            bytes_received,
                            stream_start.elapsed(),
                            last_chunk_at.elapsed(),
                        )));
                        return;
                    }
                };

                bytes_received += chunk.len();
                last_chunk_at = std::time::Instant::now();
                buffer.extend_from_slice(&chunk);

                // Process complete SSE lines.
                loop {
                    let line = match super::take_sse_line(&mut buffer) {
                        Ok(Some(line)) => line,
                        Ok(None) => break,
                        Err(err) => {
                            yield Err(anyhow::anyhow!("{err}"));
                            return;
                        }
                    };

                    if line.is_empty() || line.starts_with(':') {
                        continue;
                    }

                    if let Some(data) = super::extract_sse_data_value(&line) {
                        if data == "[DONE]" {
                            done = true;
                            break;
                        }

                        let event: Value = match serde_json::from_str(data) {
                            Ok(v) => v,
                            Err(e) => {
                                logging::warn(format!(

View on GitHub (pinned to 8880682c63)

Solutions

  1. Capture the yielded {err} detail - it names the exact framing violation (line length vs UTF-8)
  2. Reproduce with curl -N --raw and the same headers to see the raw bytes the parser sees
  3. Disable proxy compression and buffering for text/event-stream routes
  4. If the provider returns a JSON error body with an SSE content type, handle it at the HTTP status layer before streaming
  5. Retry once - single corrupted responses do happen transiently
Defensive patterns

Strategy: try-catch

Try / catch

// Inspect the yielded framing error detail before deciding
match stream.next().await {
    Some(Err(e)) if e.to_string().contains("line") || e.to_string().contains("utf") => {
        log::warn!("SSE framing violation: {e}"); // capture raw bytes on next attempt
        return Err(e); // do not retry blindly - framing bugs are deterministic
    }
    other => handle(other),
}

Prevention

When it happens

Trigger: A gateway injects an HTML error page or bare JSON error mid-stream while keeping content-type event-stream; a very long data line (large base64/image payload) exceeds the line limit; invalid UTF-8 bytes from a misbehaving proxy; response compression applied where the parser expects plain bytes.

Common situations: Reverse proxies that swap in branded error pages; providers answering errors with the SSE content type; enabling gzip on a streaming route; mirror endpoints that truncate responses.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@8880682c63 (2026-08-16). Data as JSON: /api/errors/99ab9646309f02fe. Report an issue: GitHub.