{"record":{"id":"5b6bdb058e88f169","repo":"ast-grep/ast-grep","slug":"unexpected-choice","errorCode":null,"errorMessage":"Unexpected choice","messagePattern":"Unexpected choice","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/cli/src/print/interactive_print.rs","lineNumber":366,"sourceCode":"      let display = display[index].clone();\n      interactive.inner.process(display)?;\n      interactive.inner.print_diff_title(&titles, index)?;\n      break match interactive.prompt_edit() {\n        '\\t' => {\n          index = (index + 1) % len;\n          clear()?;\n          continue;\n        }\n        'y' => InteractionChoice::Yes(confirmed),\n        'a' => InteractionChoice::All(confirmed),\n        'e' => {\n          let pos = confirmed.first_line;\n          open_in_editor(path, pos)?;\n          InteractionChoice::No\n        }\n        'q' => InteractionChoice::Quit,\n        'n' => InteractionChoice::No,\n        _ => return Err(anyhow::anyhow!(\"Unexpected choice\")),\n      };\n    };\n    Ok(ret)\n  })\n}\n\nfn apply_rewrite(diffs: Diffs<()>) -> String {\n  let mut new_content = String::new();\n  let old_content = diffs.old_source;\n  let mut start = 0;\n  for mut diff_list in diffs.contents {\n    let diff = diff_list.remove(0);\n    let range = diff.range;\n    new_content.push_str(&old_content[start..range.start]);\n    new_content.push_str(&diff.replacement);\n    start = range.end;\n  }\n  // add trailing statements","sourceCodeStart":348,"sourceCodeEnd":384,"githubUrl":"https://github.com/ast-grep/ast-grep/blob/fc2b1530db74de49131b725221de98036a552a9f/crates/cli/src/print/interactive_print.rs#L348-L384","documentation":"print_diff_and_prompt_action maps the keystroke typed at the diff prompt to an InteractionChoice; any character outside the recognized set (y/e/q/n branches) hits the default arm and returns this bare \"Unexpected choice\" error.","triggerScenarios":"The user (or an automated input source) presses a key at the diff prompt that is not one of the accepted choices — e.g. Enter, arrow keys rendering as escape sequences, or piped bytes.","commonSituations":"Piping scripted input into the interactive prompt; terminals sending multi-byte sequences for arrow keys; users pressing unsupported keys expecting other behavior.","solutions":["Press one of the documented keys shown in the prompt (y/e/q/n).","If keys are misinterpreted (arrows etc.), use a standard terminal without key-translation quirks.","For automation, supply exact single-character responses or use non-interactive mode."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":"// surface invalid keypresses before they reach the CLI\nlet resp = prompt_key();\nif !matches!(resp, 'y' | 'e' | 'q' | 'n') {\n    eprintln!(\"Unsupported key '{resp}'; use y/e/q/n.\");\n}\n","preventionTips":["Only press the documented keys (y/e/q/n) at diff prompts.","Avoid piping raw bytes (arrows, Enter) into interactive prompts.","Use non-interactive mode when input is scripted."],"tags":["cli","interactive","invalid-input"],"backgroundTag":"invalid-user-input","analyzedSha":"fc2b1530db74de49131b725221de98036a552a9f","analyzedAt":"2026-09-05T18:06:27.540Z","contentChangedAt":"2026-09-05T18:06:27.540Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}