Hmbown/CodeWhale · error · anyhow::Error

Selection out of range

Error message

Selection out of range

What it means

prompt_choice parsed a number but options.get(n-1) found no entry — the choice exceeds the menu's 1-based range (or arithmetic underflow was saturated), so the selection is rejected.

Source

Thrown at crates/tui/src/remote_setup/mod.rs:261

    for (idx, opt) in options.iter().enumerate() {
        println!("  {:>2}. {}", idx + 1, opt);
    }
    print!("Enter a number: ");
    io::stdout().flush()?;

    let mut input = String::new();
    io::stdin().read_line(&mut input)?;
    let input = input.trim();
    if input.is_empty() {
        bail!("No selection made.");
    }
    let n: usize = input
        .parse()
        .map_err(|_| anyhow::anyhow!("Invalid input: {input}"))?;
    options
        .get(n.saturating_sub(1))
        .map(|_| n - 1)
        .ok_or_else(|| anyhow::anyhow!("Selection out of range"))
}

/// Generate a runtime token from two random v4 UUIDs (OS CSPRNG via uuid),
/// matching the existing token-generation pattern in this crate.
fn generate_runtime_token() -> String {
    let a = uuid::Uuid::new_v4().simple().to_string();
    let b = uuid::Uuid::new_v4().simple().to_string();
    format!("{a}{b}")
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn generated_token_is_long_and_hex() {
        let t = generate_runtime_token();
        assert_eq!(t.len(), 64, "two simple uuids = 64 hex chars");

View on GitHub (pinned to 0c42157ee5)

Solutions

  1. Choose a number between 1 and the last option shown
  2. Press Enter to cancel and re-run the command
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/tui/src/remote_setup/mod.rs:261 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Hmbown/CodeWhale@0c42157ee5 (2026-08-20). Data as JSON: /api/errors/58bced878394b189. Report an issue: GitHub.