diff options
| author | liv <mokou@fastmail.com> | 2023-09-26 11:02:05 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-26 11:02:05 +0200 |
| commit | da3d55ba03d310a937a2795116a669e274859655 (patch) | |
| tree | 3e6a89201c89d1f57ffc535104243bdc07744d5c /src | |
| parent | e1bd5ef8587139653b0b17e9eeb415358e8ef60c (diff) | |
| parent | b88c23897f27ff5aa7d700f0bc16a289068445d5 (diff) | |
Merge pull request #1690 from jyn514/error-handling
Give a more helpful error when a file is missing
Diffstat (limited to 'src')
| -rw-r--r-- | src/exercise.rs | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/exercise.rs b/src/exercise.rs index 07251db..2c740fb 100644 --- a/src/exercise.rs +++ b/src/exercise.rs @@ -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 }; |
