{"record":{"id":"c15a5ffbe0abc20c","repo":"juspay/hyperswitch","slug":"failed-to-build-the-test-response","errorCode":null,"errorMessage":"failed to build the test response","messagePattern":"failed to build the test response","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/external_services/src/http_client/boundary.rs","lineNumber":266,"sourceCode":"    /// Three `set-cookie` headers must survive capture and reconstruct as three.\n    ///\n    /// Fails on the `insert`-per-name capture this replaced, which kept one value\n    /// per name and so recorded a single cookie.\n    #[test]\n    fn repeated_headers_survive_capture_and_reconstruct() {\n        let mut builder = http::Response::builder().status(200);\n        for (name, value) in [\n            (\"x-request-id\", \"req-1\"),\n            (\"set-cookie\", \"a=1\"),\n            (\"set-cookie\", \"b=2\"),\n            (\"set-cookie\", \"c=3\"),\n        ] {\n            builder = builder.header(name, value);\n        }\n        let source = reqwest::Response::from(\n            builder\n                .body(bytes::Bytes::from_static(b\"{}\"))\n                .expect(\"failed to build the test response\"),\n        );\n\n        let result: CustomResult<reqwest::Response, HttpClientError> = Ok(source);\n        let (captured, _) = response_result(&result);\n        let captured = captured.expose();\n\n        let reconstructed =\n            replay_response(&captured).expect(\"a captured response must reconstruct\");\n        let cookies: Vec<&str> = reconstructed\n            .headers()\n            .get_all(\"set-cookie\")\n            .iter()\n            .filter_map(|value| value.to_str().ok())\n            .collect();\n        assert_eq!(\n            cookies,\n            [\"a=1\", \"b=2\", \"c=3\"],\n            \"every set-cookie value must survive the round trip\"","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/juspay/hyperswitch/blob/afd92843521ced2c6856b98ae4ea332e75102d88/crates/external_services/src/http_client/boundary.rs#L248-L284","documentation":"A test helper builds an in-memory `reqwest::Response` via `http::Response::Builder` and calls `.expect(\"failed to build the test response\")`. If the builder is misused (e.g. an invalid header name/value passed to `.header()`), building the body panics inside the test `repeated_headers_survive_capture_and_reconstruct`.","triggerScenarios":"The header name/value pairs in the test's list are invalid (illegal characters, non-visible-ASCII values), causing `ResponseBuilder::body()` to return Err and the expect to panic.","commonSituations":"Editing the repeated-headers test fixture with a header value containing invalid bytes or a malformed header name.","solutions":["Fix the offending header name/value in the test fixture to be valid HTTP header tokens","Use `HeaderValue::from_bytes(...)` in a checked loop and skip/report invalid entries instead of passing raw strings"],"exampleFix":"// before\nbuilder = builder.header(name, value);\n// after\nlet val = http::HeaderValue::from_str(value).expect(\"test header value must be valid\");\nbuilder = builder.header(name, val);","handlingStrategy":"validation","validationCode":"if let Err(e) = http::HeaderValue::from_str(value) { panic!(\"invalid test header {name}: {e}\"); }","typeGuard":"fn is_valid_header(name: &str, value: &str) -> bool {\n    http::HeaderName::try_from(name).is_ok() && http::HeaderValue::try_from(value).is_ok()\n}","tryCatchPattern":"builder.body(body).unwrap_or_else(|e| panic!(\"failed to build the test response: {e}\"))","preventionTips":["Validate fixture headers with HeaderValue::try_from before building","Keep header fixtures limited to visible ASCII"],"tags":["rust","tests","http","header"],"backgroundTag":"invalid-argument-format","analyzedSha":"afd92843521ced2c6856b98ae4ea332e75102d88","analyzedAt":"2026-09-18T01:18:02.947Z","contentChangedAt":"2026-09-18T01:18:02.947Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}