nikivdev/code · error

Selection out of range.

Error message

Selection out of range.

What it means

run_flow_agent_capture (public API in src/agents.rs) runs the flow agent and captures final text. It requires the external `gen` tool directly — find_gen() is called unconditionally (no claude/opencode fallback here) — and bails with the install-message if gen is not found.

Source

Thrown at src/agents.rs:277

    println!("Select an agents profile:");
    for (index, profile) in profiles.iter().enumerate() {
        println!("  {}) {}", index + 1, profile);
    }
    print!("choice> ");
    io::stdout().flush()?;

    let stdin = io::stdin();
    let line = stdin.lock().lines().next();
    let input = match line {
        Some(Ok(value)) => value.trim().to_string(),
        _ => "".to_string(),
    };
    if input.is_empty() {
        bail!("No profile selected.");
    }
    let idx: usize = input.parse().context("invalid selection")?;
    if idx == 0 || idx > profiles.len() {
        bail!("Selection out of range.");
    }
    Ok(profiles[idx - 1].clone())
}

struct AgentEntry {
    name: String,
    display: String,
    path: Option<PathBuf>,
}

struct FzfAgentResult<'a> {
    entry: &'a AgentEntry,
    with_args: bool,
}

fn run_fuzzy_agents() -> Result<()> {
    let entries = build_agent_entries()?;
    if entries.is_empty() {

View on GitHub (pinned to a747e741ae)

Solutions

  1. Install gen: cd <gen_repo_hint> && f install.
  2. Set GEN_REPO env var to the local gen repo checkout before calling the API.
  3. In library code, validate find_gen()-equivalent availability up front and surface a friendly setup error.

Example fix

// before
let out = agents::run_flow_agent_capture(prompt)?; // panics-path: gen not found
// after
+ if std::env::var("GEN_REPO").is_err() {
+     std::env::set_var("GEN_REPO", "/home/user/src/gen");
+ }
let out = agents::run_flow_agent_capture(prompt)?;
Defensive patterns

Strategy: try-catch

Validate before calling

std::env::var("GEN_REPO").map_err(|_| "set GEN_REPO before calling run_flow_agent_capture")?;

Try / catch

match agents::run_flow_agent_capture(prompt) {
    Err(e) if e.to_string().contains("gen not found") => {
        eprintln!("setup: cd <gen repo> && f install, or export GEN_REPO");
        String::new() // or a fallback path
    }
    Ok(text) => text,
}

Prevention

When it happens

Trigger: Any programmatic call to flow::agents::run_flow_agent_capture(prompt) on a machine where the gen repo/binary cannot be located (not installed, GEN_REPO unset or wrong).

Common situations: Embedding flow as a library on a new machine without the gen dependency; CI jobs that install flow but not gen; GEN_REPO pointing to a stale path after a repo move.

Related errors


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