{"record":{"id":"ba9365b547d21f80","repo":"jdx/mise","slug":"expected-y-yes-or-n-no-got","errorCode":null,"errorMessage":"expected y/yes or n/no, got {:?}","messagePattern":"expected y/yes or n/no, got (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/ui/prompt.rs","lineNumber":143,"sourceCode":"/// error for anything else -- silently rereading what someone typed as \"no\" would\n/// be worse than telling them it was not understood.\n///\n/// `None` means stdin reached EOF without an answer -- the one case `demand`\n/// gets wrong (it applies the default) and the reason this exists.\nfn parse_confirm_answer(line: Option<&str>, default_yes: bool) -> eyre::Result<Confirmation> {\n    let Some(line) = line else {\n        return Ok(Confirmation::Unanswered);\n    };\n    let answer = line.trim().to_lowercase();\n    if answer.is_empty() {\n        return Ok(default_answer(default_yes));\n    }\n    if \"yes\".starts_with(&answer) {\n        Ok(Confirmation::Yes)\n    } else if \"no\".starts_with(&answer) {\n        Ok(Confirmation::No)\n    } else {\n        eyre::bail!(\"expected y/yes or n/no, got {:?}\", line.trim())\n    }\n}\n\nfn default_answer(default_yes: bool) -> Confirmation {\n    if default_yes {\n        Confirmation::Yes\n    } else {\n        Confirmation::No\n    }\n}\n\npub(crate) fn confirm_with_all<S: Into<String>>(message: S) -> eyre::Result<Confirmation> {\n    let _lock = MUTEX.lock().unwrap(); // Prevent multiple prompts at once\n    ctrlc::show_cursor_after_ctrl_c();\n\n    if !can_prompt_dialog() {\n        return Ok(Confirmation::Unavailable);\n    }","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/ui/prompt.rs#L125-L161","documentation":"mise's interactive confirm prompt reads a line from stdin and accepts only 'y', 'yes', 'n', 'no' (case-insensitive prefix match). Any other non-empty answer makes parse_confirm_answer bail with this message echoing the trimmed input. It exists to force an explicit yes/no rather than guessing.","triggerScenarios":"read_confirm_from_stdin receiving input that is neither a y/yes nor n/no prefix — e.g. piping unexpected text into a command that prompts, typing 'ok', '1', or pasting multi-word text at the prompt.","commonSituations":"Automating mise (CI scripts) where stdin contains unrelated data; users typing 'Y ' with odd whitespace is fine (trimmed) but 'yeah', 'sure', or an empty-then-garbage answer fails; redirecting files into mise commands that confirm trust/install prompts.","solutions":["Answer with y/yes or n/no exactly at the prompt.","In scripts, avoid the prompt: pipe 'y' (echo y | mise ...) or use non-interactive flags/settings (e.g. --yes / MISE_YES=1).","Ensure stdin redirection actually supplies a valid answer, not unrelated file content."],"exampleFix":"// before (CI)\nmise install < some.log\n// after\necho y | mise install   # or: mise install --yes","handlingStrategy":"try-catch","validationCode":"function isConfirmAnswer(s) {\n  const a = String(s).trim().toLowerCase();\n  return ['y', 'yes', 'n', 'no'].some(v => v.startsWith(a) && a.length > 0);\n}","typeGuard":null,"tryCatchPattern":"// Rust\nmatch read_confirm_from_stdin(default) {\n    Ok(c) => c,\n    Err(e) if e.to_string().contains(\"expected y/yes or n/no\") => {\n        eprintln!(\"Please answer y or n\");\n        // re-prompt or fall back to default\n        default\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Run mise non-interactively in CI (--yes / MISE_YES=1) instead of piping ad-hoc stdin.","When piping answers, ensure the piped data is exactly y/n.","Train users/scripts to answer only y, yes, n, or no at prompts."],"tags":["mise","prompt","stdin","interactive"],"backgroundTag":"invalid-enum-value","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}