{"record":{"id":"b811e621bae4e98c","repo":"Hmbown/CodeWhale","slug":"invalid-input-input","errorCode":null,"errorMessage":"Invalid input: {input}","messagePattern":"Invalid input: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/tui/src/remote_setup/mod.rs","lineNumber":257,"sourceCode":"/// Print a numbered menu, read a 1-based selection from stdin, return the index.\nfn prompt_choice(title: &str, options: &[String]) -> Result<usize> {\n    println!();\n    println!(\"{title}:\");\n    for (idx, opt) in options.iter().enumerate() {\n        println!(\"  {:>2}. {}\", idx + 1, opt);\n    }\n    print!(\"Enter a number: \");\n    io::stdout().flush()?;\n\n    let mut input = String::new();\n    io::stdin().read_line(&mut input)?;\n    let input = input.trim();\n    if input.is_empty() {\n        bail!(\"No selection made.\");\n    }\n    let n: usize = input\n        .parse()\n        .map_err(|_| anyhow::anyhow!(\"Invalid input: {input}\"))?;\n    options\n        .get(n.saturating_sub(1))\n        .map(|_| n - 1)\n        .ok_or_else(|| anyhow::anyhow!(\"Selection out of range\"))\n}\n\n/// Generate a runtime token from two random v4 UUIDs (OS CSPRNG via uuid),\n/// matching the existing token-generation pattern in this crate.\nfn generate_runtime_token() -> String {\n    let a = uuid::Uuid::new_v4().simple().to_string();\n    let b = uuid::Uuid::new_v4().simple().to_string();\n    format!(\"{a}{b}\")\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n","sourceCodeStart":239,"sourceCodeEnd":275,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/remote_setup/mod.rs#L239-L275","documentation":"prompt_choice parses interactive menu input as a usize index. Any non-empty input that is not a valid unsigned integer (e.g. letters, negative numbers, floats) produces this error; empty input produces a separate 'No selection made' error.","triggerScenarios":"At a remote setup prompt, typing text or a malformed number instead of the numeric option number (e.g. 'aws', '1.5', '-1', or a number with stray characters).","commonSituations":"Users typing the option's name instead of its number, pasting values with whitespace/characters, keyboard locale issues, or automated input feeding wrong tokens.","solutions":["Enter the numeric option number shown next to the choice (1-based)","Trim whitespace/paste artifacts and retry","Only digits are accepted — no letters, signs, or decimals","For automation, pipe the index (e.g. `echo 2 |`) rather than the option name"],"exampleFix":"// before\nCloud: aws\n// after\nCloud: 2   # numeric position of 'aws' in the list","handlingStrategy":"try-catch","validationCode":"let t = input.trim();\nif t.is_empty() || t.parse::<usize>().is_err() {\n    eprintln!(\"Enter a numeric option, e.g. 1\");\n}","typeGuard":null,"tryCatchPattern":"match prompt_choice(&prompt, &options) {\n    Err(e) if e.to_string().starts_with(\"Invalid input\") => {\n        // re-prompt once with a hint\n        eprintln!(\"{e} — enter the option's number\");\n        prompt_choice(&prompt, &options)\n    }\n    other => other,\n}","preventionTips":["Always answer menu prompts with the numeric index","Trim pasted input and strip stray characters","For automation, pipe digits only","Read the menu before answering; do not type option names"],"tags":["cli","input-validation","interactive","parsing"],"backgroundTag":"invalid-argument-format","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}