{"record":{"id":"de38029ff1c70f46","repo":"nikivdev/code","slug":"suggested-command-exited-unsuccessfully-with-statu","errorCode":null,"errorMessage":"suggested command exited unsuccessfully with status {}","messagePattern":"suggested command exited unsuccessfully with status (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/ask.rs","lineNumber":271,"sourceCode":"\n    let args = match tokens.first().map(|token| token.as_str()) {\n        Some(\"f\") | Some(\"flow\") => tokens[1..].to_vec(),\n        _ => tokens,\n    };\n    if args.is_empty() {\n        bail!(\"Suggested command is incomplete.\");\n    }\n\n    let exe = std::env::current_exe()?;\n    let status = Command::new(&exe)\n        .args(&args)\n        .stdin(Stdio::inherit())\n        .stdout(Stdio::inherit())\n        .stderr(Stdio::inherit())\n        .status()\n        .with_context(|| format!(\"failed to execute suggested command via {}\", exe.display()))?;\n    if !status.success() {\n        bail!(\n            \"suggested command exited unsuccessfully with status {}\",\n            status\n        );\n    }\n    Ok(())\n}\n\nfn confirm_with_tui(title: &str, lines: &[String], prompt: &str) -> Result<bool> {\n    if let Some(answer) = opentui_prompt::confirm(title, lines, true) {\n        return Ok(answer);\n    }\n    confirm_default_yes(prompt)\n}\n\nfn confirm_default_yes(prompt: &str) -> Result<bool> {\n    print!(\"{}\", prompt);\n    io::stdout().flush()?;\n","sourceCodeStart":253,"sourceCodeEnd":289,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/ask.rs#L253-L289","documentation":"After execute_suggested_command spawns the suggested command as a child process (with inherited stdio), it checks the exit status. Any non-zero exit is re-raised as a context-rich anyhow error so the failure of the suggestion surfaces in the parent's error chain.","triggerScenarios":"The user executes an accepted AI suggestion and the spawned 'f ...' process exits with a non-zero status code (build failure, task failure, clap usage error, etc.).","commonSituations":"The AI suggested a valid-but-doomed command (e.g. 'f run' with a broken task); the underlying task fails at runtime; clap rejects the suggested arguments.","solutions":["Read the error chain: the child's own stderr is inherited, so the real failure reason is printed above this message — fix that root cause","Validate suggested commands (tasks exist, args sane) before offering them for execution","Add known-likely flags to the suggested command, or re-prompt the AI when the command fails","Treat the exit status in automation: match on status codes you care about instead of letting it bail generically"],"exampleFix":"// before\nif !status.success() {\n    bail!(\"suggested command exited unsuccessfully with status {}\", status);\n}\n// after\nif let Some(code) = status.code() {\n    if code != 0 {\n        bail!(\"suggested command exited unsuccessfully with status {}\", code);\n    }\n} else {\n    bail!(\"suggested command was terminated by a signal\");\n}","handlingStrategy":"try-catch","validationCode":"// Pre-flight: ensure the suggested subcommand exists before executing\nfn suggestion_references_valid_subcommand(tokens: &[String], valid: &HashSet<String>) -> bool {\n    tokens.first().map(|t| t.to_ascii_lowercase()).map(|t| {\n        let t = if t == \"flow\" { \"f\".to_string() } else { t };\n        valid.contains(&t)\n    }).unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"match execute_suggested_command(tokens) {\n    Err(e) if e.to_string().contains(\"exited unsuccessfully\") => {\n        eprintln!(\"The suggested command failed; see output above for the root cause.\");\n    }\n    Err(e) => return Err(e),\n    Ok(()) => {}\n}","preventionTips":["Remember the child's stderr is inherited — read it for the real cause","Validate the suggestion against valid subcommands before execution","Run risky suggestions with user confirmation","Capture the child exit code programmatically if you need different handling per failure"],"tags":["process","exit-status","cli"],"backgroundTag":"nonzero-exit-status","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}