Hmbown/CodeWhale · error · anyhow::Error
translate: Anthropic Messages response did not contain text…
Error message
translate: Anthropic Messages response did not contain text content
What it means
When translating text through an Anthropic Messages-format endpoint, the client joins all text content blocks of the response and requires non-empty text. If the response contained no text content (or only whitespace after trimming), it bails rather than returning an empty translation.
Solutions
- Retry the translation request; transient model/refusal responses often succeed on retry.
- Inspect the raw response (enable logging) to see what content blocks were returned; switch to a model that returns plain text for translation.
- If a proxy is in front of the provider, verify it forwards the Messages response unmodified.
- Check provider status/quota — degraded endpoints may return empty content.
Defensive patterns
Strategy: try-catch
Try / catch
match translate_result {
Err(e) if e.to_string().contains("did not contain text content") => {
log::warn!("Anthropic returned no text blocks; retrying once");
translate_result = translate(input).await;
}
r => r?,
} Prevention
- Retry once on empty-content translation errors before surfacing to the user.
- Prefer models known to emit plain text for translation tasks.
- Log raw response blocks when this error occurs to spot proxies mangling payloads.
When it happens
Trigger: The Anthropic Messages response contains only non-text blocks (e.g. tool_use), or an empty/whitespace-only text array — typically caused by an unexpected model reply or a degraded/proxy endpoint.
Common situations: Hitting a proxy/gateway that returns a mangled Messages payload; a model that replies with tool calls instead of text; quota/refusal responses shaped as non-text blocks.
Related errors
- translate: provider response did not contain text content
- Anthropic API error (HTTP )
- Anthropic stream error
- API key not found. Run 'codewhale auth set --provider '…
- Codewhale runtime file contained only stream deltas or…
AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22).
Data as JSON: /api/errors/add467740d450b74.
Report an issue: GitHub.
Appendix: source
Thrown at crates/tui/src/client.rs:2371
temperature: None,
top_p: None,
}
}
fn translation_text_from_response(response: &MessageResponse) -> Result<String> {
let translated = response
.content
.iter()
.filter_map(|block| match block {
ContentBlock::Text { text, .. } => Some(text.as_str()),
_ => None,
})
.collect::<Vec<_>>()
.join("")
.trim()
.to_string();
if translated.is_empty() {
bail!("translate: Anthropic Messages response did not contain text content");
}
Ok(translated)
}
fn xiaomi_mimo_base_url_uses_token_plan(base_url: &str) -> bool {
let normalized = base_url.trim().to_ascii_lowercase();
let without_scheme = normalized
.strip_prefix("https://")
.or_else(|| normalized.strip_prefix("http://"))
.unwrap_or(&normalized);
let host = without_scheme
.split(['/', '?', '#'])
.next()
.unwrap_or_default();
let host = host.split(':').next().unwrap_or(host);
host.starts_with("token-plan-") && host.ends_with(".xiaomimimo.com")
}
View on GitHub (pinned to 73e0f67d83)