{"record":{"id":"4da9d6cae8fb84ca","repo":"Hmbown/CodeWhale","slug":"command-is-required","errorCode":null,"errorMessage":"Command is required","messagePattern":"Command is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/lib.rs","lineNumber":8916,"sourceCode":"        exclude_slash_tmp,\n        cwd,\n        timeout_ms,\n        command,\n    } = args.command;\n\n    let policy = parse_sandbox_policy(\n        &policy,\n        network,\n        writable_root,\n        exclude_tmpdir,\n        exclude_slash_tmp,\n    )?;\n    let cwd = cwd.unwrap_or_else(|| std::env::current_dir().unwrap_or_else(|_| PathBuf::from(\".\")));\n    let timeout = Duration::from_millis(timeout_ms.clamp(1000, 600_000));\n\n    let (program, args) = command\n        .split_first()\n        .ok_or_else(|| anyhow::anyhow!(\"Command is required\"))?;\n    let spec =\n        CommandSpec::program(program, args.to_vec(), cwd.clone(), timeout).with_policy(policy);\n    let manager = SandboxManager::new();\n    let exec_env = manager.prepare(&spec);\n\n    let mut cmd = Command::new(exec_env.program());\n    cmd.args(exec_env.args())\n        .current_dir(&exec_env.cwd)\n        .stdout(Stdio::piped())\n        .stderr(Stdio::piped());\n    child_env::apply_to_command(&mut cmd, child_env::string_map_env(&exec_env.env));\n\n    let mut child = cmd\n        .spawn()\n        .map_err(|e| anyhow::anyhow!(\"Failed to run command: {e}\"))?;\n    let stdout_handle = child\n        .stdout\n        .take()","sourceCodeStart":8898,"sourceCodeEnd":8934,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/8880682c63083a91624de936797efa3ce9e498fd/crates/tui/src/lib.rs#L8898-L8934","documentation":"Returned by run_sandbox_command when the command vector is empty, so split_first() yields no program to execute. It is a usage-contract error: the sandbox runner requires at least one element (the program) before it can build a CommandSpec. The policy, cwd, and timeout are parsed first, so those must already be valid.","triggerScenarios":"Invoking the sandbox run subcommand with an empty command list: `--command=` with an empty value, an argv built by a script where a variable expands to nothing (unquoted empty shell variable), or a programmatic caller passing Vec::new() as command to SandboxCommand::Run.","commonSituations":"Shell scripts forwarding unset variables into the CLI, wrapper tools that split an empty string into zero arguments, or clap arg definitions allowing zero values (num_args(0..)) for the command field.","solutions":["Pass a non-empty command: at minimum the program name, followed by its arguments","If driving SandboxCommand::Run programmatically, assert !command.is_empty() before calling","Tighten the CLI definition to require at least one value (num_args(1..) with a non-empty value_parser) so the error surfaces at parse time with clap's own message"],"exampleFix":"// before: empty argv reaches the runner\nlet (program, args) = command.split_first()\n    .ok_or_else(|| anyhow::anyhow!(\"Command is required\"))?;\n// after: reject at the CLI boundary\n#[arg(required = true, num_args = 1..)]\ncommand: Vec<String>,","handlingStrategy":"validation","validationCode":"// Rust: gate before dispatch\nif command.is_empty() {\n    return Err(anyhow::anyhow!(\"sandbox run requires a program plus optional args\"));\n}","typeGuard":"// Narrow an optional command into a guaranteed non-empty invocation\nfn as_invocation(cmd: &[String]) -> Option<(&str, &[String])> {\n    cmd.split_first().map(|(p, a)| (p.as_str(), a))\n}","tryCatchPattern":null,"preventionTips":["Quote variables when scripting the CLI so empty expansions are visible","Require at least one command element in arg definitions (num_args(1..))","Unit-test the empty-argv path in wrappers around SandboxCommand::Run"],"tags":["cli","sandbox","validation","usage"],"backgroundTag":null,"analyzedSha":"8880682c63083a91624de936797efa3ce9e498fd","analyzedAt":"2026-08-16T11:31:27.956Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}