{"record":{"id":"1274c36125ddae05","repo":"BoundaryML/baml","slug":"failed-to-fetch-url","errorCode":null,"errorMessage":"Failed to fetch: {url}","messagePattern":"Failed to fetch: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/tracing/api_wrapper/mod.rs","lineNumber":144,"sourceCode":"    host_name: String,\n    log_redaction_enabled: bool,\n    log_redaction_placeholder: String,\n    pub max_log_chunk_chars: usize,\n}\n\nimpl CompleteAPIConfig {\n    pub(self) async fn post<T: DeserializeOwned>(&self, path: &str, body: &Value) -> Result<T> {\n        let url = format!(\"{}/{}\", self.base_url, path);\n\n        let req = self\n            .client\n            .post(&url)\n            .json(body)\n            .bearer_auth(&self.api_key)\n            .build()?;\n\n        let Ok(res) = self.client.execute(req).await else {\n            return Err(anyhow::anyhow!(\"Failed to fetch: {url}\"));\n        };\n        let status = res.status();\n        let body = res.text().await?;\n\n        if !status.is_success() {\n            return Err(anyhow::anyhow!(\n                \"Failed to submit BAML log: {url}. Status: {status}\\nBody: {body}\"\n            ));\n        }\n\n        match serde_json::from_str::<T>(&body) {\n            Ok(v) => Ok(v),\n            Err(e) => Err(anyhow::anyhow!(\n                \"Failed to parse response: {url}. Status: {status}\\nBody: {body} \\nError: {:?}\",\n                e\n            )),\n        }\n    }","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/tracing/api_wrapper/mod.rs#L126-L162","documentation":"The tracing API wrapper's `post` method sends an authenticated JSON POST to the BAML event/logging endpoint. If the HTTP client fails to execute the request at all (connection failure, DNS error, TLS problem, etc.), the `let-else` bails with 'Failed to fetch: {url}' — this fires before any HTTP status is available.","triggerScenarios":"Any transport-level failure during `self.client.execute(req)` in post(): the collector URL host is unreachable, network is down, DNS resolution fails, TLS handshake fails, or the request could not be constructed and the execute future returns Err.","commonSituations":"BOUNDARY_ collector URL pointing to a nonexistent host or closed port; corporate proxy/firewall blocking the endpoint; running locally (or in a CI job) without network access while the tracer tries to submit a session.","solutions":["Verify the configured BOUNDARY/collector URL is reachable: `curl -v <url>` from the same machine.","Check network connectivity, DNS, and proxy settings (HTTP_PROXY/HTTPS_PROXY) for the environment running BAML.","Confirm the API endpoint host/port and TLS setup (correct scheme https vs http, correct port)."],"exampleFix":"// before (unreachable collector)\nBOUNDARY_URL=http://localhost:9999   // nothing listening\n// after\nBOUNDARY_URL=http://localhost:7287   // correct, running collector","handlingStrategy":"retry","validationCode":"// Shell: reachability pre-check before enabling tracing submission\ncurl -fsS --max-time 5 \"$BOUNDARY_URL\" >/dev/null || { echo \"BOUNDARY_URL unreachable: $BOUNDARY_URL\"; }","typeGuard":null,"tryCatchPattern":"// Rust: retry transient fetch failures with backoff\nfor attempt in 0..3 {\n    match wrapper.post(&url, &body).await {\n        Ok(v) => break,\n        Err(e) if e.to_string().contains(\"Failed to fetch\") && attempt < 2 => {\n            tokio::time::sleep(Duration::from_millis(500 * (attempt + 1))).await;\n        }\n        Err(e) => return Err(e),\n    }\n}","preventionTips":["Verify the BOUNDARY collector URL with curl from the deployment environment.","Configure HTTP(S)_PROXY correctly in restricted networks.","Make log submission failure non-fatal for your app (log-and-continue) when tracing is optional."],"tags":["network","http","tracing","fetch"],"backgroundTag":"http-request-failed","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}