coding-horror/basic-computer-games · error
Your input is not correct
Error message
Your input is not correct
What it means
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.
Source
Thrown at 41_Guess/rust/src/main.rs:107
println!("of a number between 1 and any limit you want.\n");
println!("Then you have to guess what it is\n");
println!("What limit do you want?");
let inp = get_input().trim().parse::<i64>().unwrap();
if inp >= 2 {
inp
}
else {
set_limit()
}
}
fn get_input() -> String {
let mut input = String::new();
io::stdin()
.read_line(&mut input)
.expect("Your input is not correct");
input
}
View on GitHub (pinned to 5301155192)
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
Example fix
// before
fn get_input() -> String {
let mut input = String::new();
io::stdin()
.read_line(&mut input)
.expect("Your input is not correct");
input
}
// after
fn get_input() -> String {
let mut input = String::new();
let _ = io::stdin().read_line(&mut input);
input
} Defensive patterns
Strategy: fallback
Try / catch
fn get_input() -> String {
let mut input = String::new();
let _ = io::stdin().read_line(&mut input);
input
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Error reading from stdin
- Error reading line.
- ~~Failed reading line!~~
- Failed to get Input
- Failed to read line
AI-assisted analysis of coding-horror/basic-computer-games@5301155192 (2026-08-13).
Data as JSON: /api/errors/0ec75c1503ef28e9.
Report an issue: GitHub.