Skip to content

Commit

Permalink
Merge pull request rust-lang#1690 from jyn514/error-handling
Browse files Browse the repository at this point in the history
Give a more helpful error when a file is missing
  • Loading branch information
shadows-withal authored Sep 26, 2023
2 parents e1bd5ef + b88c238 commit da3d55b
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/exercise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,21 @@ path = "{}.rs""#,
}

pub fn state(&self) -> State {
let mut source_file =
File::open(&self.path).expect("We were unable to open the exercise file!");
let mut source_file = File::open(&self.path).unwrap_or_else(|e| {
panic!(
"We were unable to open the exercise file {}! {e}",
self.path.display()
)
});

let source = {
let mut s = String::new();
source_file
.read_to_string(&mut s)
.expect("We were unable to read the exercise file!");
source_file.read_to_string(&mut s).unwrap_or_else(|e| {
panic!(
"We were unable to read the exercise file {}! {e}",
self.path.display()
)
});
s
};

Expand Down

0 comments on commit da3d55b

Please sign in to comment.