{"record":{"id":"8cccd850cff6c80f","repo":"ducaale/xh","slug":"request-body-from-stdin-and-raw-cannot-be-mixed-pass-ignore","errorCode":null,"errorMessage":"Request body from stdin and --raw cannot be mixed. Pass --ignore-stdin to ignore standard input.","messagePattern":"Request body from stdin and --raw cannot be mixed\\. Pass --ignore-stdin to ignore standard input\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/main.rs","lineNumber":129,"sourceCode":"    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()?\n    };\n\n    let method = args.method.unwrap_or_else(|| body.pick_method());\n    log::debug!(\"HTTP method: {method}\");\n\n    let mut client = Client::builder()\n        .http1_title_case_headers()","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/ducaale/xh/blob/2404aceecc08b0b2d100fedc96f57745cd5904dc/src/main.rs#L111-L147","documentation":"The CLI found both piped stdin content and the --raw flag, which are two competing sources for the raw request body. It refuses to guess and asks the user to pick one, using --ignore-stdin to silence the piped body.","triggerScenarios":"use_stdin is true (stdin piped, --ignore-stdin not set) and args.raw.is_some() in run(), after the request-items check passes.","commonSituations":"Running `echo x | xh POST url --raw '{...}'` in scripts; CI environments where stdin is a pipe even when unused; combining raw body flags with heredoc/stdin patterns out of habit.","solutions":["Pass --ignore-stdin so only the --raw body is sent.","Remove --raw and send the body via stdin instead.","Feed the raw content through stdin only (e.g. heredoc) and drop the --raw argument.","Redirect stdin from /dev/null when --raw is used in scripts."],"exampleFix":"// before\ncat body.json | xh POST example.org --raw '{\"a\":1}'\n// after\nxh POST example.org --raw '{\"a\":1}' < /dev/null","handlingStrategy":"validation","validationCode":"if !std::io::stdin().is_terminal() && !ignore_stdin && args.raw.is_some() {\n    eprintln!(\"--raw conflicts with piped stdin; add --ignore-stdin or < /dev/null\");\n    std::process::exit(2);\n}","typeGuard":null,"tryCatchPattern":"match run(args) {\n    Err(e) if e.to_string().contains(\"--raw cannot be mixed\") => {\n        eprintln!(\"tip: keep --raw and add --ignore-stdin\");\n    }\n    other => other,\n}","preventionTips":["Pair every --raw usage with --ignore-stdin in scripts.","Choose one body source: --raw, stdin, or request items.","Redirect stdin from /dev/null when the body is provided via flags.","Review heredoc patterns that leave stdin as a pipe."],"tags":["cli","stdin","raw-body","http"],"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"}