SeleniumHQ/selenium · error · anyhow::Error
Error parsing JSON from URL {} {}
Error message
Error parsing JSON from URL {} {} What it means
Raised by parse_json_from_url() in rust/src/downloads.rs when serde_json::from_str fails on the body fetched from a URL. This wraps the serde error and the URL so the caller knows which endpoint returned malformed JSON. It is used to parse version-discovery endpoints (CfT, NuGet, msedgedriver) and any deserialization failure is fatal for that discovery path.
Source
Thrown at rust/src/downloads.rs:108
pub async fn read_redirect_from_link(
http_client: &Client,
url: String,
log: &Logger,
) -> Result<String, Error> {
parse_version(
http_client.get(&url).send().await?.url().path().to_string(),
log,
)
}
pub fn parse_json_from_url<T>(http_client: &Client, url: &str) -> Result<T, Error>
where
T: Serialize + for<'a> Deserialize<'a>,
{
let content = read_content_from_link(http_client, url)?;
match serde_json::from_str(&content) {
Ok(json) => Ok(json),
Err(err) => Err(anyhow!(format!(
"Error parsing JSON from URL {} {}",
url, err
))),
}
}
View on GitHub (pinned to aa36b38e69)
Solutions
- Manually fetch the URL and confirm the body is valid JSON matching the expected schema.
- Retry to rule out a transient partial response.
- Check for proxy/TLS interception that rewrites the body.
- If the upstream schema changed, update the deserializing struct T.
Defensive patterns
Strategy: try-catch
Validate before calling
// Rust: validate JSON shape before deserializing into the typed struct
let content = read_content_from_link(http_client, url)?;
let v: serde_json::Value = serde_json::from_str(&content)
.map_err(|e| anyhow!("Endpoint {} returned non-JSON: {}", url, e))?; Try / catch
match parse_json_from_url::<T>(http_client, url) {
Ok(data) => Ok(data),
Err(e) if e.to_string().contains("Error parsing JSON") => {
log::warn!("Version endpoint {} returned malformed JSON; falling back", url);
fallback_discovery()
}
Err(e) => Err(e),
} Prevention
- Log the raw body when JSON parsing fails for diagnosis.
- Pin the deserializing structs to the documented API schema.
- Detect HTML/error pages before attempting JSON parse.
When it happens
Trigger: read_content_from_link returns successfully but the text is not valid JSON for the expected type T. Causes: endpoint returns HTML error page, a truncated response, a schema mismatch where the JSON doesn't fit T, or a 200 with an empty body.
Common situations: A version endpoint is temporarily replaced by a maintenance HTML page; corporate proxy injects a block page; the upstream API schema changed; TLS interception corrupts the body.
Related errors
- Unsuccessful response ({}) for URL {}
- {} {} not available for download on {} (minimum version: {})
- Format for file {} cannot be inferred
- Wrong browser/driver version
- Downloaded file cannot be uncompressed ({} extension)
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/18f83200522a47a7.
Report an issue: GitHub.