{"record":{"id":"99ab9646309f02fe","repo":"Hmbown/CodeWhale","slug":"err-99ab96","errorCode":null,"errorMessage":"{err}","messagePattern":"\\{err\\}","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/client/responses.rs","lineNumber":264,"sourceCode":"                            bytes_received,\n                            stream_start.elapsed(),\n                            last_chunk_at.elapsed(),\n                        )));\n                        return;\n                    }\n                };\n\n                bytes_received += chunk.len();\n                last_chunk_at = std::time::Instant::now();\n                buffer.extend_from_slice(&chunk);\n\n                // Process complete SSE lines.\n                loop {\n                    let line = match super::take_sse_line(&mut buffer) {\n                        Ok(Some(line)) => line,\n                        Ok(None) => break,\n                        Err(err) => {\n                            yield Err(anyhow::anyhow!(\"{err}\"));\n                            return;\n                        }\n                    };\n\n                    if line.is_empty() || line.starts_with(':') {\n                        continue;\n                    }\n\n                    if let Some(data) = super::extract_sse_data_value(&line) {\n                        if data == \"[DONE]\" {\n                            done = true;\n                            break;\n                        }\n\n                        let event: Value = match serde_json::from_str(data) {\n                            Ok(v) => v,\n                            Err(e) => {\n                                logging::warn(format!(","sourceCodeStart":246,"sourceCodeEnd":282,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/8880682c63083a91624de936797efa3ce9e498fd/crates/tui/src/client/responses.rs#L246-L282","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Capture the yielded {err} detail - it names the exact framing violation (line length vs UTF-8)","Reproduce with curl -N --raw and the same headers to see the raw bytes the parser sees","Disable proxy compression and buffering for text/event-stream routes","If the provider returns a JSON error body with an SSE content type, handle it at the HTTP status layer before streaming","Retry once - single corrupted responses do happen transiently"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Inspect the yielded framing error detail before deciding\nmatch stream.next().await {\n    Some(Err(e)) if e.to_string().contains(\"line\") || e.to_string().contains(\"utf\") => {\n        log::warn!(\"SSE framing violation: {e}\"); // capture raw bytes on next attempt\n        return Err(e); // do not retry blindly - framing bugs are deterministic\n    }\n    other => handle(other),\n}","preventionTips":["Disable response compression on streaming routes","Log the raw first 1KB of any failing stream to see injected error pages","Assert content-type is text/event-stream before handing bytes to the SSE parser"],"tags":["sse","parsing","proxy","utf-8","streaming"],"backgroundTag":null,"analyzedSha":"8880682c63083a91624de936797efa3ce9e498fd","analyzedAt":"2026-08-16T11:31:27.956Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}