xai-org/x-algorithm · error · anyhow::Error
{e}
Error message
{e} What it means
Returned by fetch_following_list_internal when serde_json fails to parse the Strato response body as StratoResponse<Vec<String>>. The warn log already prints the error and a 300-char response preview, which usually reveals whether the body is HTML (error page), truncated, or a different schema.
Source
Thrown at thunder/strato_client.rs:159
match serde_json::from_str::<StratoResponse<Vec<String>>>(&text) {
Ok(result) => {
metrics::STRATO_REQUESTS
.with_label_values(&["fetch_following_list", "success"])
.inc();
Ok(result.v)
}
Err(e) => {
metrics::STRATO_REQUESTS
.with_label_values(&["fetch_following_list", "parse_error"])
.inc();
warn!(
"Failed to parse following list response for {}: {}. Response preview: {}",
user_id,
e,
&text[..text.len().min(300)]
);
Err(anyhow!(e))
}
}
}
pub async fn fetch_user_metadata(&self, user_id: i64) -> Result<Option<UserMetadata>> {
let start = std::time::Instant::now();
let url = format!("{}/op/fetch/gizmoduck/composite.User", self.base_url);
let payload = serde_json::json!([user_id, (serde_json::json!({}), ["profile", "counts"])]);
let response = self
.client
.post(&url)
.header("Content-Type", "application/json")
.body(serde_json::to_string(&payload)?)
.send()
.awaitView on GitHub (pinned to 24c60942c5)
Solutions
- Inspect the warn log's response preview to identify what was actually returned
- If HTML from a proxy, check the Strato endpoint URL/LB config and any required headers (auth, accept-encoding)
- If the schema changed, update StratoResponse<Vec<String>> to match the current Strato API shape
- Verify HTTP client decompression settings so gzip/br bodies are decoded before parsing
Example fix
// before
match serde_json::from_str::<StratoResponse<Vec<String>>>(&text) {
Ok(result) => { ... }
Err(e) => Err(anyhow!(e)),
}
// after
match serde_json::from_str::<StratoResponse<Vec<String>>>(&text) {
Ok(result) => { ... }
Err(e) => Err(anyhow::anyhow!(
"strato parse failed for user {user_id}: {e}; body starts: {}",
&text[..text.len().min(120)]
)),
} Defensive patterns
Strategy: try-catch
Validate before calling
// sanity check body shape before parse: starts with '{' and contains "data" key Try / catch
match serde_json::from_str::<StratoResponse<Vec<String>>>(&text) { Ok(r) => ..., Err(e) if text.trim_start().starts_with('<') => anyhow::bail!("proxy HTML page returned"), Err(e) => Err(anyhow!(e)) } Prevention
- Assert Content-Type is JSON on responses
- Pin schema with contract tests against Strato
- Log body previews on parse failure (already done) and alert on spikes
When it happens
Trigger: Calling fetch_following_list when Strato returns a 200 with an unexpected body: an HTML error/proxy page, a different response schema after an API change, or truncated/garbled payloads from network issues.
Common situations: A proxy or LB intercepting the request and returning HTML; Strato API version change altering the JSON shape; encoding/compression (gzip not decompressed) issues; partial responses on connection resets.
Related errors
- {metric_label} fetch failed after retries: {e}
- response.status().to_string()
- ttl=-1
- Strato error code {}: {}
- Post metadata is required
AI-assisted analysis of xai-org/x-algorithm@24c60942c5 (2026-08-28).
Data as JSON: /api/errors/98a93c1483e4f3e5.
Report an issue: GitHub.