{"record":{"id":"369d28d51614af24","repo":"ducaale/xh","slug":"can-t-read-request-from-multiple-files","errorCode":null,"errorMessage":"Can't read request from multiple files","messagePattern":"Can't read request from multiple files","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/request_items.rs","lineNumber":429,"sourceCode":"        for item in self.items {\n            match item {\n                RequestItem::DataField { .. }\n                | RequestItem::JsonField(..)\n                | RequestItem::DataFieldFromFile { .. }\n                | RequestItem::JsonFieldFromFile(..) => {\n                    return Err(anyhow!(\n                        \"Request body (from a file) and request data (key=value) cannot be mixed.\"\n                    ));\n                }\n                RequestItem::FormFile {\n                    key,\n                    file_name,\n                    file_type,\n                    file_name_header,\n                } => {\n                    assert!(key.is_empty());\n                    if body.is_some() {\n                        return Err(anyhow!(\"Can't read request from multiple files\"));\n                    }\n                    body = Some(Body::File {\n                        file_type: file_type\n                            .as_deref()\n                            .or_else(|| mime_guess::from_path(&file_name).first_raw())\n                            .map(HeaderValue::from_str)\n                            .transpose()?,\n                        file_name: expand_tilde(file_name),\n                        file_name_header,\n                    });\n                }\n                RequestItem::HttpHeader(..)\n                | RequestItem::HttpHeaderFromFile(..)\n                | RequestItem::HttpHeaderToUnset(..)\n                | RequestItem::UrlParam(..)\n                | RequestItem::UrlParamFromFile(..) => {}\n            }\n        }","sourceCodeStart":411,"sourceCodeEnd":447,"githubUrl":"https://github.com/ducaale/xh/blob/2404aceecc08b0b2d100fedc96f57745cd5904dc/src/request_items.rs#L411-L447","documentation":"xh refuses to build a request body when more than one file would supply it. In body_from_file, multipart file items and the -f single-file body path all feed the single `body` variable; a second file item finds body already Some and aborts, because an HTTP request body can only have one source here.","triggerScenarios":"Passing multiple standalone file arguments (or a request-items file entry after another file) so that `body` is already Some(Body::File{..}) when the next file is processed, e.g. `xh POST url @a.json @b.json` or combining a body file with a form file item.","commonSituations":"Users mimicking curl's multiple @file behavior; scripts appending extra file arguments by mistake; confusion between `-f` form fields (multiple allowed) and a single request body file.","solutions":["Use only one file for the request body; remove the extra file argument","If multiple parts are needed, use multipart form syntax: -f or key=value@file items instead of a bare body file","Combine the files into one file first, or use stdin (e.g. `cat a b | xh POST url`)","Check the constructed CLI/script for duplicated --body-file/@file arguments"],"exampleFix":"// before\nxh POST example.org/upload @part1.bin @part2.bin\n// after\nxh -f POST example.org/upload part1@part1.bin part2@part2.bin","handlingStrategy":"validation","validationCode":"// count file-sourced body parts before invoking\nlet file_args = std::env::args().filter(|a| a == \"@\" || a.starts_with('@')).count();\nif file_args > 1 { eprintln!(\"pass at most one body file; use -f key@file for parts\"); std::process::exit(2); }","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"multiple files\") => eprintln!(\"Use -f key=value@file for multiple parts\"),\n    Err(e) => return Err(e),\n    Ok(v) => Ok(v),\n}","preventionTips":["Use at most one bare body file per request","Use multipart form items (key@file) when uploading several files","Review generated scripts for duplicated @file/--body-file flags"],"tags":["cli","request-body","multipart"],"backgroundTag":"mutually-exclusive-options","analyzedSha":"2404aceecc08b0b2d100fedc96f57745cd5904dc","analyzedAt":"2026-09-13T19:13:33.814Z","contentChangedAt":"2026-09-13T19:13:33.814Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}