Skip to content

Commit

Permalink
Handle invalid data from file
Browse files Browse the repository at this point in the history
  • Loading branch information
dwisiswant0 committed Jul 6, 2021
1 parent a165821 commit 06e6128
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ pub fn from_file(filepath: impl AsRef<Path>) -> Vec<String> {
Ok(file) => file,
Err(err) => {
errors::show(format!("Open '{}': {}.", filepath.display(), err));
process::exit(1);
process::exit(1)
}
};
let buf = BufReader::new(open);

buf.lines().map(|l| l.expect("Couldn't parse lines")).collect()
buf.lines().map(|l| l.unwrap_or_else(|err| {
errors::show(format!("Open '{}': {}.", filepath.display(), err));
process::exit(1)
})).collect()
}

0 comments on commit 06e6128

Please sign in to comment.