nikivdev/code · error

suggested command exited unsuccessfully with status {}

Error message

suggested command exited unsuccessfully with status {}

What it means

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.

Source

Thrown at src/ask.rs:271

    let args = match tokens.first().map(|token| token.as_str()) {
        Some("f") | Some("flow") => tokens[1..].to_vec(),
        _ => tokens,
    };
    if args.is_empty() {
        bail!("Suggested command is incomplete.");
    }

    let exe = std::env::current_exe()?;
    let status = Command::new(&exe)
        .args(&args)
        .stdin(Stdio::inherit())
        .stdout(Stdio::inherit())
        .stderr(Stdio::inherit())
        .status()
        .with_context(|| format!("failed to execute suggested command via {}", exe.display()))?;
    if !status.success() {
        bail!(
            "suggested command exited unsuccessfully with status {}",
            status
        );
    }
    Ok(())
}

fn confirm_with_tui(title: &str, lines: &[String], prompt: &str) -> Result<bool> {
    if let Some(answer) = opentui_prompt::confirm(title, lines, true) {
        return Ok(answer);
    }
    confirm_default_yes(prompt)
}

fn confirm_default_yes(prompt: &str) -> Result<bool> {
    print!("{}", prompt);
    io::stdout().flush()?;

View on GitHub (pinned to a747e741ae)

Solutions

  1. 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
  2. Validate suggested commands (tasks exist, args sane) before offering them for execution
  3. Add known-likely flags to the suggested command, or re-prompt the AI when the command fails
  4. Treat the exit status in automation: match on status codes you care about instead of letting it bail generically

Example fix

// before
if !status.success() {
    bail!("suggested command exited unsuccessfully with status {}", status);
}
// after
if let Some(code) = status.code() {
    if code != 0 {
        bail!("suggested command exited unsuccessfully with status {}", code);
    }
} else {
    bail!("suggested command was terminated by a signal");
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-flight: ensure the suggested subcommand exists before executing
fn suggestion_references_valid_subcommand(tokens: &[String], valid: &HashSet<String>) -> bool {
    tokens.first().map(|t| t.to_ascii_lowercase()).map(|t| {
        let t = if t == "flow" { "f".to_string() } else { t };
        valid.contains(&t)
    }).unwrap_or(false)
}

Try / catch

match execute_suggested_command(tokens) {
    Err(e) if e.to_string().contains("exited unsuccessfully") => {
        eprintln!("The suggested command failed; see output above for the root cause.");
    }
    Err(e) => return Err(e),
    Ok(()) => {}
}

Prevention

When it happens

Trigger: 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.).

Common situations: 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.

Related errors


AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01). Data as JSON: /api/errors/de38029ff1c70f46. Report an issue: GitHub.