{"record":{"id":"bffe143003f8da2e","repo":"coding-horror/basic-computer-games","slug":"failed-to-read-the-line","errorCode":null,"errorMessage":"Failed to read the line","messagePattern":"Failed to read the line","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"20_Buzzword/rust/src/main.rs","lineNumber":80,"sourceCode":"\n    let mut continue_running: bool = true;\n\n    while continue_running {\n        let mut first_word: bool = true;\n        for section in &words {\n            if !first_word {\n                print!(\" \");\n            }\n            first_word = false;\n            print!(\"{}\", section.choose(&mut rand::thread_rng()).unwrap());\n        }\n        print!(\"\\n\\n? \");\n        io::stdout().flush().unwrap();\n\n        let mut cont_question: String = String::new();\n        io::stdin()\n            .read_line(&mut cont_question)\n            .expect(\"Failed to read the line\");\n        if !cont_question.to_uppercase().starts_with(\"Y\") {\n            continue_running = false;\n        }\n    }\n    println!(\"Come back when you need help with another report!\\n\");\n\n}\n\n\n/////////////////////////////////////////////////////////////////////////\n//\n// Porting Notes\n//\n//   The original program stored all 39 words in one array, then\n//   built the buzzword phrases by randomly sampling from each of the\n//   three regions of the array (1-13, 14-26, and 27-39).\n//\n//   Here, we're storing the words for each section in separate","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/coding-horror/basic-computer-games/blob/5301155192d91d74d337899cecc59dbda59c4c17/20_Buzzword/rust/src/main.rs#L62-L98","documentation":"A panic via .expect(\"Failed to read the line\") on io::stdin().read_line() in the Buzzword Rust port, used at the end of each generated phrase to ask whether the user wants another phrase. read_line returns Err only on I/O-level failure (closed stdin, EOF, broken pipe); the Yes/No parsing is done afterward on the String. The expect aborts the process if stdin cannot be read at the continue prompt.","triggerScenarios":"stdin closed or exhausted before the '? continue (Y/N)' prompt; piped input that ends before the user answers; running with `< /dev/null`.","commonSituations":"Piping a fixture without a trailing Y/N line; headless/CI runs with no open stdin; a feeder that closes stdin after generating one phrase's worth of input.","solutions":["Append a Y/N line in piped input for each continue prompt.","Run interactively.","Replace .expect with `match` that sets continue_running=false on read error and exits gracefully."],"exampleFix":"// before\nio::stdin().read_line(&mut cont_question).expect(\"Failed to read the line\");\n\n// after\nif io::stdin().read_line(&mut cont_question).is_err() {\n    continue_running = false;\n}","handlingStrategy":"fallback","validationCode":"// The continue answer can default to 'stop' on read failure; no pre-check needed.","typeGuard":null,"tryCatchPattern":"// On read error, end the loop gracefully\nmatch io::stdin().read_line(&mut cont_question) {\n    Ok(_) => { if !cont_question.to_uppercase().starts_with('Y') { continue_running = false; } }\n    Err(_) => { continue_running = false; }\n}","preventionTips":["Match read_line instead of .expect for continue prompts.","Treat EOF as 'No' to end cleanly.","Append a Y/N line per iteration when piping."],"tags":["rust","stdin","io","panic","expect","continue-prompt"],"backgroundTag":null,"analyzedSha":"5301155192d91d74d337899cecc59dbda59c4c17","analyzedAt":"2026-08-13T19:29:00.979Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}