{"record":{"id":"a0f1ca3bc781d5ca","repo":"coding-horror/basic-computer-games","slug":"error-getting-your-input","errorCode":null,"errorMessage":"Error Getting your input","messagePattern":"Error Getting your input","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"47_Hi-Lo/rust/src/main.rs","lineNumber":63,"sourceCode":"                println!(\"YOUR GUESS IS TOO LOW.\\n\");\n            } else {\n                println!(\"YOUR GUESS IS TOO HIGH.\\n\");\n            }\n\n            // if 6 tries are over make total jackpot amount to zero\n            if i == 5 {\n                total = 0;\n                println!(\n                    \"YOU BLEW IT...TOO BAD...THE NUMBER WAS {}\\n\",\n                    jackpot_amount\n                );\n            }\n        }\n        println!(\"PLAY AGAIN (YES OR NO)?\");\n        let mut tocontinue = String::new();\n        io::stdin()\n            .read_line(&mut tocontinue)\n            .expect(\"Error Getting your input\");\n        let tocontinue = tocontinue.trim().to_ascii_uppercase();\n        if tocontinue.eq(\"YES\") {\n            println!(\"\\n\");\n            continue;\n        } else {\n            println!(\"\\nSO LONG.  HOPE YOU ENJOYED YOURSELF!!!\\n\");\n            break;\n        }\n    }\n}\n","sourceCodeStart":45,"sourceCodeEnd":74,"githubUrl":"https://github.com/coding-horror/basic-computer-games/blob/5301155192d91d74d337899cecc59dbda59c4c17/47_Hi-Lo/rust/src/main.rs#L45-L74","documentation":"In 47_Hi-Lo, after each jackpot round the game asks 'PLAY AGAIN (YES OR NO)?' and reads the response via io::stdin().read_line(&mut tocontinue).expect(\"Error Getting your input\"). The response is compared case-insensitively to 'YES' to decide whether to continue. The .expect() panics on stdin I/O failure.","triggerScenarios":"The game finishes a round and prompts to continue, but stdin is at EOF or the read fails. A non-'YES' answer already triggers the 'SO LONG' exit, so EOF should logically behave the same way.","commonSituations":"Piped input that ends after a game round, pressing Ctrl+D at the play-again prompt, or automated tests that stop feeding input after one game.","solutions":["Replace .expect() with .unwrap_or_default() — an empty string won't equal 'YES', so the game correctly prints 'SO LONG' and exits","Use if read_line(...).is_err() to break the outer loop","Return early from the function on Err"],"exampleFix":"// before\nlet mut tocontinue = String::new();\nio::stdin()\n    .read_line(&mut tocontinue)\n    .expect(\"Error Getting your input\");\nlet tocontinue = tocontinue.trim().to_ascii_uppercase();\n\n// after\nlet mut tocontinue = String::new();\nlet _ = io::stdin().read_line(&mut tocontinue);\nlet tocontinue = tocontinue.trim().to_ascii_uppercase();","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"let mut tocontinue = String::new();\nlet _ = io::stdin().read_line(&mut tocontinue);\n// empty string != \"YES\", so the game prints 'SO LONG' and exits,\n// which is the correct response to EOF at this prompt","preventionTips":["For yes/no prompts where non-yes already means exit, I/O failure should produce the same exit — use let _ = instead of .expect()","Recognize that EOF at a 'play again?' prompt is the user's way of saying 'no more' — treat it accordingly","Avoid .expect() on the final input in a game session where the natural response to EOF is 'stop playing'"],"tags":["rust","stdin","read-line","panic","expect","io-error","eof","interactive","cli","yes-no"],"backgroundTag":null,"analyzedSha":"5301155192d91d74d337899cecc59dbda59c4c17","analyzedAt":"2026-08-13T19:29:00.979Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}