{"record":{"id":"39afd0325974dc2c","repo":"coding-horror/basic-computer-games","slug":"closing","errorCode":null,"errorMessage":"closing","messagePattern":"closing","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"02_Amazing/rust/src/main.rs","lineNumber":168,"sourceCode":"    println!(\".\");\n    //rest of maze\n    for r in 0..height {\n        print!(\"I\");\n        for c in 0..width {\n            if walls[r][c]<2 {print!(\"  I\");}\n            else {print!(\"   \");}\n        }\n        println!();\n        for c in 0..width {\n            if walls[r][c] == 0 || walls[r][c]==2 {print!(\":--\");}\n            else {print!(\":  \");}\n        }\n        println!(\".\");\n    }\n\n    //stops the program from ending until you give input, useful when running a compiled .exe\n    println!(\"\\n\\npress ENTER to exit\");\n    io::stdin().read_line(&mut String::new()).expect(\"closing\");\n}\n\nfn get_user_input(prompt: &str) -> usize {\n    //DATA\n    let mut raw_input = String::new(); // temporary variable for user input that can be parsed later\n\n    //input loop\n    return loop {\n\n        //print prompt\n        println!(\"{}\", prompt);\n\n        //read user input from standard input, and store it to raw_input\n        raw_input.clear(); //clear input\n        io::stdin().read_line(&mut raw_input).expect( \"CANNOT READ INPUT!\");\n\n        //from input, try to read a number\n        match raw_input.trim().parse::<usize>() {","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/coding-horror/basic-computer-games/blob/5301155192d91d74d337899cecc59dbda59c4c17/02_Amazing/rust/src/main.rs#L150-L186","documentation":"A panic via .expect(\"closing\") on io::stdin().read_line() at the end of the Amazing maze program, which prints 'press ENTER to exit' and waits so a compiled .exe window doesn't close immediately. The expect panics if stdin cannot be read at that final pause (closed stdin, EOF, broken pipe). The label 'closing' is just the panic message, not a descriptive error.","triggerScenarios":"The program finishes drawing the maze and reaches the 'press ENTER to exit' pause, but stdin is closed (e.g. input was fully consumed from a pipe, or stdin is /dev/null, or the pipe broke).","commonSituations":"Piping all game input and letting the stream end before the final ENTER; running with `< /dev/null`; a GUI-launched .exe whose stdin handle is invalid.","solutions":["If piping input, include a trailing newline so the final read_line returns Ok.","Run interactively so stdin stays open until you press ENTER.","Replace .expect(\"closing\") with `let _ = io::stdin().read_line(...)` to ignore read failure at the exit pause."],"exampleFix":"// before\nio::stdin().read_line(&mut String::new()).expect(\"closing\");\n\n// after: tolerate EOF at the exit prompt\nlet _ = io::stdin().read_line(&mut String::new());","handlingStrategy":"fallback","validationCode":"// No validation needed; the read is a best-effort pause. Just ignore its result.","typeGuard":null,"tryCatchPattern":"// Discard the result so EOF doesn't panic\nlet _ = io::stdin().read_line(&mut String::new());","preventionTips":["For exit/continue prompts, never .expect the read; the result is unimportant.","Include a trailing newline in piped input if you do want the pause to return.","Consider gating the 'press ENTER' pause behind is_terminal() so non-interactive runs skip it."],"tags":["rust","stdin","io","panic","expect","exit-prompt"],"backgroundTag":null,"analyzedSha":"5301155192d91d74d337899cecc59dbda59c4c17","analyzedAt":"2026-08-13T19:29:00.979Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}