{"record":{"id":"0ec75c1503ef28e9","repo":"coding-horror/basic-computer-games","slug":"your-input-is-not-correct","errorCode":null,"errorMessage":"Your input is not correct","messagePattern":"Your input is not correct","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"41_Guess/rust/src/main.rs","lineNumber":107,"sourceCode":"    println!(\"of a number between 1 and any limit you want.\\n\");\n    println!(\"Then you have to guess what it is\\n\");\n    println!(\"What limit do you want?\");\n\n    let inp = get_input().trim().parse::<i64>().unwrap();\n\n    if inp >= 2 {\n        inp\n    }\n    else {\n        set_limit()\n    }\n}\n\nfn get_input() -> String {\n    let mut input = String::new();\n    io::stdin()\n        .read_line(&mut input)\n        .expect(\"Your input is not correct\");\n    input\n}\n","sourceCodeStart":89,"sourceCodeEnd":110,"githubUrl":"https://github.com/coding-horror/basic-computer-games/blob/5301155192d91d74d337899cecc59dbda59c4c17/41_Guess/rust/src/main.rs#L89-L110","documentation":"In 41_Guess, get_input reads a letter guess via io::stdin().read_line(&mut input).expect(\"Your input is not correct\"). The error message is misleading — 'not correct' implies a validation failure, but the panic actually triggers on an I/O error (EOF, broken pipe, invalid fd). The function returns the raw String; parse/validation happens in the caller.","triggerScenarios":"The game prompts 'WHAT IS YOUR GUESS?' and stdin is at EOF, or the read syscall fails. Invalid guesses (wrong letters, empty strings) are handled by the caller's comparison logic, not by this function.","commonSituations":"Piped input that runs out before all guesses are made, Ctrl+D at the guess prompt, or CI tests that provide insufficient input. The misleading message makes debugging harder because a developer might look for validation bugs instead of I/O issues.","solutions":["Rename the message to accurately reflect the failure: 'Failed to read from stdin' instead of 'Your input is not correct'","Replace .expect() with .unwrap_or_default() to return an empty string on failure, which the caller's guess comparison will handle as a wrong guess","Return Option<String> to let the caller detect EOF and end the game"],"exampleFix":"// before\nfn get_input() -> String {\n    let mut input = String::new();\n    io::stdin()\n        .read_line(&mut input)\n        .expect(\"Your input is not correct\");\n    input\n}\n\n// after\nfn get_input() -> String {\n    let mut input = String::new();\n    let _ = io::stdin().read_line(&mut input);\n    input\n}","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"fn get_input() -> String {\n    let mut input = String::new();\n    let _ = io::stdin().read_line(&mut input);\n    input\n}","preventionTips":["Use accurate error messages — 'Your input is not correct' on an I/O failure misleads developers into searching for validation bugs","Use let _ = on reads that return raw strings, letting the caller's comparison logic handle empty input","When the caller already handles invalid input gracefully, the input helper should not panic on any failure"],"tags":["rust","stdin","read-line","panic","expect","io-error","eof","interactive","misleading-message","cli"],"backgroundTag":null,"analyzedSha":"5301155192d91d74d337899cecc59dbda59c4c17","analyzedAt":"2026-08-13T19:29:00.979Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}