{"record":{"id":"0a22f95b0645b7aa","repo":"BoundaryML/baml","slug":"failed-to-parse-url","errorCode":null,"errorMessage":"Failed to parse URL: {}","messagePattern":"Failed to parse URL: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/internal/llm_client/traits/mod.rs","lineNumber":834,"sourceCode":"            return Some((mime_type, base64));\n        }\n    }\n\n    None\n}\n\nasync fn fetch_with_proxy(\n    url: &str,\n    proxy_url: Option<&str>,\n) -> Result<reqwest::Response, anyhow::Error> {\n    let client = reqwest::Client::new();\n\n    let request = if let Some(proxy) = proxy_url {\n        let new_proxy_url = format!(\n            \"{}{}\",\n            proxy,\n            url.parse::<url::Url>()\n                .map_err(|e| anyhow::anyhow!(\"Failed to parse URL: {}\", e))?\n                .path()\n        );\n        client.get(new_proxy_url).header(\"baml-original-url\", url)\n    } else {\n        client.get(url)\n    };\n\n    let response = request.send().await?;\n    Ok(response)\n}\n\n#[cfg(test)]\nmod tests_scrub {\n    use std::collections::HashMap;\n\n    use baml_types::BamlMap;\n    use serde_json::json;\n","sourceCodeStart":816,"sourceCodeEnd":852,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/internal/llm_client/traits/mod.rs#L816-L852","documentation":"When a proxy is configured, BAML rewrites the media URL by appending the target URL's path to the proxy base; the URL failed to parse with the url crate, so the path cannot be extracted and the request aborts.","triggerScenarios":"A proxy_url is set in the runtime context and media_url.url is malformed (missing scheme, invalid characters, whitespace) so url::parse fails.","commonSituations":"Typo'd media URLs (missing https://); URLs with unescaped spaces or non-ASCII characters; env-var proxy settings accidentally injected into the URL field; template variables not rendered.","solutions":["Fix the media URL so it is a fully valid absolute URL (scheme + host)","URL-encode special characters (spaces, unicode) before passing the URL","Check that any templating/env substitution produced the intended URL rather than a literal placeholder","If you don't need the proxy, unset the proxy_url configuration"],"exampleFix":"// before\nurl \"example.com/doc pdf.pdf\"\n// after\nurl \"https://example.com/doc%20pdf.pdf\"","handlingStrategy":"validation","validationCode":"function isValidUrl(u) {\n  try { const parsed = new URL(u); return !!parsed.protocol && !!parsed.hostname; }\n  catch { return false; }\n}\nif (!isValidUrl(mediaUrl)) throw new Error(`Invalid media URL: ${mediaUrl}`);","typeGuard":"const isHttpUrl = (s) => { try { const u = new URL(s); return u.protocol === 'http:' || u.protocol === 'https:'; } catch { return false; } };","tryCatchPattern":"try {\n  await runBamlFn();\n} catch (e) {\n  if (/Failed to parse URL/.test(String(e.message))) {\n    console.error('Malformed media URL passed to BAML:', mediaUrl);\n  }\n  throw e;\n}","preventionTips":["Validate URLs with a URL parser before passing them to BAML","Encode spaces/unicode with encodeURIComponent in path segments","Check templating/env substitution isn't leaking literal placeholders into URLs"],"tags":["url","http","proxy","baml"],"backgroundTag":"invalid-url-format","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}