Skip to content

Commit

Permalink
Handle invalid UTF-8 instead of just crashing.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiers committed Mar 15, 2024
1 parent d9fabf6 commit 553a09f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ fn main() -> Result<(), ureq::Error> {
query.clear();
print!("=> ");
stdout().flush().unwrap();
if (stdin().read_line(&mut query).expect("Can't read from stdin")) == 0 {
/* Exit on EOF */
return Ok(());
match stdin().read_line(&mut query) {
Ok(n) => if n == 0 { return Ok(()); /* Exit on EOF */ }
Err(e) => eprintln!("Error: {e}")
}
query = query.trim().to_string();
}
Expand Down

0 comments on commit 553a09f

Please sign in to comment.