{"record":{"id":"cf4fa152751938d3","repo":"ducaale/xh","slug":"request-body-from-stdin-and-request-data-key-value-cannot-be","errorCode":null,"errorMessage":"Request body (from stdin) and request data (key=value) cannot be mixed. Pass --ignore-stdin to ignore standard input.","messagePattern":"Request body \\(from stdin\\) and request data \\(key=value\\) cannot be mixed\\. Pass --ignore-stdin to ignore standard input\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/main.rs","lineNumber":122,"sourceCode":"\n    if args.curl {\n        to_curl::print_curl_translation(args)?;\n        return Ok(ExitCode::SUCCESS);\n    }\n\n    let (mut headers, headers_to_unset) = args.request_items.headers()?;\n    let url = url_with_query(args.url, &args.request_items.query()?);\n    log::debug!(\"Complete URL: {url}\");\n\n    let use_stdin = !(args.ignore_stdin || io::stdin().is_terminal() || test_pretend_term());\n\n    let body = if use_stdin {\n        if !args.request_items.is_body_empty() {\n            if args.multipart {\n                // Multipart bodies are never \"empty\", so we can get here without request items\n                return Err(anyhow!(\"Cannot build a multipart request body from stdin\"));\n            } else {\n                return Err(anyhow!(\n                    \"Request body (from stdin) and request data (key=value) cannot be mixed. \\\n                    Pass --ignore-stdin to ignore standard input.\"\n                ));\n            }\n        }\n        if args.raw.is_some() {\n            return Err(anyhow!(\n                \"Request body from stdin and --raw cannot be mixed. \\\n                Pass --ignore-stdin to ignore standard input.\"\n            ));\n        }\n        let mut buffer = Vec::new();\n        io::stdin().read_to_end(&mut buffer)?;\n        Body::Raw(buffer)\n    } else if let Some(raw) = args.raw {\n        Body::Raw(raw.into_bytes())\n    } else {\n        args.request_items.body()?","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/ducaale/xh/blob/2404aceecc08b0b2d100fedc96f57745cd5904dc/src/main.rs#L104-L140","documentation":"The CLI detected piped stdin content and also request data items (key=value), which would require mixing a raw stdin body with form fields — impossible in a single request. It errors and suggests --ignore-stdin.","triggerScenarios":"use_stdin is true (stdin piped, --ignore-stdin not set), args.request_items.is_body_empty() is false, and args.multipart is false in run().","commonSituations":"Piping JSON with `echo data | xh POST url key=value`; shell scripts where stdin happens to be a pipe in CI; forgetting that a non-terminal stdin counts as a body.","solutions":["Pass --ignore-stdin to discard piped stdin and send only the key=value request items.","Remove the key=value items and send the stdin body alone (e.g. with a Content-Type header).","Move the stdin content into a request item such as field@file instead of piping.","Run from an interactive terminal or explicitly redirect stdin from /dev/null."],"exampleFix":"// before\necho '{\"a\":1}' | xh POST example.org key=value\n// after\necho '{\"a\":1}' | xh --ignore-stdin POST example.org key=value","handlingStrategy":"validation","validationCode":"if !std::io::stdin().is_terminal() && !ignore_stdin && !request_items.is_body_empty() {\n    eprintln!(\"piping a body and key=value items cannot be mixed; add --ignore-stdin\");\n    std::process::exit(2);\n}","typeGuard":null,"tryCatchPattern":"match run(args) {\n    Err(e) if e.to_string().contains(\"cannot be mixed\") => {\n        eprintln!(\"tip: add --ignore-stdin or drop the key=value items\");\n    }\n    other => other,\n}","preventionTips":["Default to --ignore-stdin in shell scripts and CI.","Send either a stdin body OR request items, never both.","Convert stdin payloads into a file and pass it with a request item when fields are needed.","Use explicit input redirection to document data flow in scripts."],"tags":["cli","stdin","http","request-body"],"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"}