{"id":"aefff98a40be6b23","repo":"seanmonstar/reqwest","slug":"builder-error","errorCode":null,"errorMessage":"builder error","messagePattern":"builder error","errorType":"exception","errorClass":"reqwest::Error","httpStatus":null,"severity":"error","filePath":"src/error.rs","lineNumber":345,"sourceCode":"\n#[derive(Debug)]\npub(crate) enum Kind {\n    Builder,\n    Request,\n    Redirect,\n    #[cfg(not(all(target_arch = \"wasm32\", any(target_os = \"unknown\", target_os = \"none\"))))]\n    Status(StatusCode, Option<hyper::ext::ReasonPhrase>),\n    #[cfg(all(target_arch = \"wasm32\", any(target_os = \"unknown\", target_os = \"none\")))]\n    Status(StatusCode),\n    Body,\n    Decode,\n    Upgrade,\n}\n\n// constructors\n\npub(crate) fn builder<E: Into<BoxError>>(e: E) -> Error {\n    Error::new(Kind::Builder, Some(e))\n}\n\npub(crate) fn body<E: Into<BoxError>>(e: E) -> Error {\n    Error::new(Kind::Body, Some(e))\n}\n\npub(crate) fn decode<E: Into<BoxError>>(e: E) -> Error {\n    Error::new(Kind::Decode, Some(e))\n}\n\npub(crate) fn request<E: Into<BoxError>>(e: E) -> Error {\n    Error::new(Kind::Request, Some(e))\n}\n\npub(crate) fn dns<E: Into<BoxError>>(e: E) -> BoxError {\n    Box::new(DnsError { inner: e.into() })\n}\n","sourceCodeStart":327,"sourceCodeEnd":363,"githubUrl":"https://github.com/seanmonstar/reqwest/blob/17e9bcb51c46edebfb6f5f2f5184b51dac4b3a7d/src/error.rs#L327-L363","documentation":"The `Kind::Builder` error, constructed by `error::builder(...)` (error.rs:344-346). It represents any failure while *building* something rather than sending it: parsing a URL string into a `Url` (into_url.rs:48), a malformed redirect `Location`, or `ClientBuilder::build()` rejecting bad TLS/identity/proxy config.","triggerScenarios":"`reqwest::get(\"not a url\")` or any `.get(str)` where the string fails `Url::parse`; `ClientBuilder::build()` failing on bad `add_root_certificate`, `identity`, `tls_built_in_root_certs`, min/max TLS version mismatch, or proxy URL parse error; a redirect `Location` header that isn't a valid URL.","commonSituations":"Typo'd URL, missing scheme (`example.com` instead of `https://example.com`), loading a `.pfx` identity that doesn't match its password, conflicting TLS settings, or a proxy env var with garbage.","solutions":["Print the wrapped source: `if let Some(s) = e.source() { eprintln!(\"{s}\"); }` — it carries the real cause (parse error, bad cert, etc.).","If from `.get(str)`, parse and validate the URL first with `url::Url::parse`.","If from `ClientBuilder::build()`, isolate which TLS/identity/proxy call introduced the failure by building incrementally.","Check error.is_builder() before assuming a network failure."],"exampleFix":"// before\nlet client = Client::builder()\n    .identity(identity)?\n    .build()?; // 'builder error' if identity/pw mismatch\n\n// after\nmatch Client::builder().identity(identity).build() {\n    Ok(c) => c,\n    Err(e) => {\n        eprintln!(\"build failed: {}\", e.source().map(|s| s.to_string()).unwrap_or_default());\n        Client::new()\n    }\n}","handlingStrategy":"try-catch","validationCode":"// Validate URLs before they reach the client.\nlet parsed = url::Url::parse(&raw).map_err(|e| anyhow!(\"bad url: {e}\"))?;\nif !matches!(parsed.scheme(), \"http\" | \"https\") {\n    return Err(anyhow!(\"scheme not allowed\"));\n}\n","typeGuard":"fn is_builder_error(e: &reqwest::Error) -> bool { e.is_builder() }\n","tryCatchPattern":"let client = match Client::builder().identity(id).build() {\n    Ok(c) => c,\n    Err(e) if e.is_builder() => {\n        log::error!(\"build failed: {}\", e.source().map(|s| s.to_string()).unwrap_or_default());\n        Client::new()\n    }\n    Err(e) => return Err(e.into()),\n};","preventionTips":["Parse and validate URLs at the system boundary, not deep in call sites.","Build Client config incrementally to localize which setting fails.","Always inspect e.source() on builder errors."],"tags":["builder","url","tls","config"],"analyzedSha":"17e9bcb51c46edebfb6f5f2f5184b51dac4b3a7d","analyzedAt":"2026-08-06T01:23:05.134Z","schemaVersion":2}