{"record":{"id":"cecbe53d2dd8134b","repo":"Hmbown/CodeWhale","slug":"anthropic-stream-error-error-type-message","errorCode":null,"errorMessage":"Anthropic stream error ({error_type}): {message}","messagePattern":"Anthropic stream error \\((.+?)\\): (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/client/anthropic.rs","lineNumber":366,"sourceCode":"                    let line = match next_sse_line(&mut buffer, ended) {\n                        Ok(Some(line)) => line,\n                        Ok(None) => break,\n                        Err(err) => {\n                            yield Err(anyhow::anyhow!(\"{err}\"));\n                            return;\n                        }\n                    };\n\n                    // `event:` lines are redundant (the data payload carries\n                    // `type`) and comment/heartbeat lines are ignorable.\n                    let Some(data) = extract_sse_data_value(&line) else {\n                        continue;\n                    };\n\n                    match convert_anthropic_sse_data(data) {\n                        Some(Ok(StreamEvent::Error { error })) => {\n                            let (error_type, message) = anthropic_error_fields(&error);\n                            yield Err(anyhow::anyhow!(\n                                \"Anthropic stream error ({error_type}): {message}\"\n                            ));\n                            return;\n                        }\n                        Some(Ok(event)) => {\n                            let is_stop = matches!(event, StreamEvent::MessageStop);\n                            yield Ok(event);\n                            if is_stop {\n                                return;\n                            }\n                        }\n                        Some(Err(e)) => {\n                            logging::warn(format!(\"Failed to parse Anthropic SSE event: {e}\"));\n                        }\n                        None => {}\n                    }\n                }\n","sourceCodeStart":348,"sourceCodeEnd":384,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/client/anthropic.rs#L348-L384","documentation":"The Anthropic SSE stream delivered an explicit error event (type \"error\" carrying an error object). The handler extracts the error.type and error.message fields and surfaces them as a Rust error, then stops the stream — this is the server reporting a failure in-band.","triggerScenarios":"Anthropic sends an SSE event {\"type\":\"error\",\"error\":{\"type\":...,\"message\":...}}: overloaded_error (server overloaded), rate_limit_error, invalid_request_error (bad model/params), api_error, authentication_error mid-stream after the connection was already established.","commonSituations":"Hitting rate limits during heavy usage; Anthropic capacity issues returning overloaded_error; an invalid model name or oversized request accepted at connection time but rejected during streaming; an API key losing validity mid-session.","solutions":["Read error_type in the message: overloaded_error/rate_limit_error → back off and retry with exponential delay","invalid_request_error → fix the request: model name, max_tokens, prompt size, parameter names","authentication_error → refresh/verify the API key","Check the Anthropic status page if overloaded_error persists across retries","Respect the Retry-After semantics / documented rate limits to avoid repeat hits"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) => {\n        let msg = e.to_string();\n        if msg.contains(\"overloaded_error\") || msg.contains(\"rate_limit_error\") {\n            tokio::time::sleep(backoff).await;\n            retry_request()\n        } else if msg.contains(\"invalid_request_error\") {\n            Err(anyhow!(\"bad request: {msg}\"))\n        } else { Err(e) }\n    }\n    Ok(v) => Ok(v),\n}","preventionTips":["Classify by the error type in the message and only retry retryable ones (overloaded/rate_limit)","Validate model name, max_tokens, and prompt size before the request","Respect documented rate limits and back off exponentially","Monitor Anthropic status and alert on repeated overloaded_error"],"tags":["api","anthropic","sse","upstream"],"backgroundTag":"upstream-api-error","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}