{"record":{"id":"8e9ca43b743364a6","repo":"openai/codex","slug":"request-build-error-0","errorCode":null,"errorMessage":"request build error: {0}","messagePattern":"request build error: (.+?)","errorType":"exception","errorClass":"TransportError","httpStatus":null,"severity":"error","filePath":"codex-rs/http-client/src/error.rs","lineNumber":25,"sourceCode":"\n#[derive(Debug, Error)]\npub enum TransportError {\n    #[error(\"http {status}: {body:?}\")]\n    Http {\n        status: StatusCode,\n        url: Option<String>,\n        headers: Option<HeaderMap>,\n        body: Option<String>,\n    },\n    #[error(\"retry limit reached\")]\n    RetryLimit,\n    #[error(\"timeout\")]\n    Timeout,\n    #[error(\"connection failed: {0}\")]\n    Connection(#[source] HttpError),\n    #[error(\"network error: {0}\")]\n    Network(String),\n    #[error(\"request build error: {0}\")]\n    Build(String),\n}\n\n#[derive(Debug, Error)]\npub enum StreamError {\n    #[error(\"stream failed: {0}\")]\n    Stream(String),\n    #[error(\"timeout\")]\n    Timeout,\n}\n","sourceCodeStart":7,"sourceCodeEnd":36,"githubUrl":"https://github.com/openai/codex/blob/339751715c64496cb86246bfb3935f40e309dd3d/codex-rs/http-client/src/error.rs#L7-L36","documentation":"TransportError::Build is returned by ReqwestTransport::build (transport.rs:53) when Request::prepare_body_for_send() fails to turn the request into wire bytes. The string is the exact reason from request.rs: 'request compression cannot be used with raw bodies', 'request compression was requested but content-encoding is already set', a serde_json serialization error, or a zstd compression error. It fires before any network I/O, so it is deterministic and retrying will not help.","triggerScenarios":"Building a Request with RequestBody::Raw combined with RequestCompression::Zstd; setting a manual Content-Encoding header while also requesting compression (request.rs:193-198); a JSON body whose encoding fails; a zstd encode_all failure (request.rs:204-208).","commonSituations":"Enabling zstd request compression uniformly in a pipeline where some callers already set Content-Encoding: gzip, or where some paths send raw (non-JSON) bodies; retrofitting compression onto existing request code without auditing headers.","solutions":["Read the message string: it names the exact conflict (raw body + compression, or existing content-encoding)","Do not combine RequestCompression with RequestBody::Raw: send JSON bodies or disable compression for raw payloads","Remove any manually inserted Content-Encoding header before requesting compression and let prepare_encoded_json insert 'zstd' itself","Call Request::into_prepared() at construction time to surface this failure early with full context instead of at send time"],"exampleFix":"// before\nlet mut req = Request::new(Method::POST, url).with_json(&body)\n    .with_compression(RequestCompression::Zstd);\nreq.headers.insert(http::header::CONTENT_ENCODING,\n    http::HeaderValue::from_static(\"gzip\")); // -> Build(\"content-encoding is already set\")\n\n// after: let the transport own Content-Encoding when compressing\nlet req = Request::new(Method::POST, url).with_json(&body)\n    .with_compression(RequestCompression::Zstd);","handlingStrategy":"validation","validationCode":"// Dry-run the exact wire preparation before handing the request to the transport\nfn request_builds(req: &Request) -> Result<(), String> {\n    req.prepare_body_for_send().map(|_| ())\n}","typeGuard":"fn is_build_error(e: &TransportError) -> bool {\n    matches!(e, TransportError::Build(_))\n}","tryCatchPattern":"Err(TransportError::Build(reason)) => {\n    // deterministic input problem: fail fast, do not retry\n    return Err(ConfigError::RequestShape(reason));\n}","preventionTips":["Call Request::into_prepared() at construction so encoding failures surface with full context before any send","Never set Content-Encoding manually when using RequestCompression; the transport owns it","Keep compression enabled only for JSON bodies; assert the body variant before enabling it","Unit-test prepare_body_for_send() for every request shape your service sends"],"tags":["request","encoding","compression","rust"],"backgroundTag":"request-body-encoding-failed","analyzedSha":"339751715c64496cb86246bfb3935f40e309dd3d","analyzedAt":"2026-08-25T05:35:09.876Z","schemaVersion":2},"datasetVersion":"2026-08-25T06:17:31.827Z"}