Skip to content

Commit da3d55b

Browse files
authored
Merge pull request #1690 from jyn514/error-handling
Give a more helpful error when a file is missing
2 parents e1bd5ef + b88c238 commit da3d55b

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/exercise.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,21 @@ path = "{}.rs""#,
201201
}
202202

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

207211
let source = {
208212
let mut s = String::new();
209-
source_file
210-
.read_to_string(&mut s)
211-
.expect("We were unable to read the exercise file!");
213+
source_file.read_to_string(&mut s).unwrap_or_else(|e| {
214+
panic!(
215+
"We were unable to read the exercise file {}! {e}",
216+
self.path.display()
217+
)
218+
});
212219
s
213220
};
214221

0 commit comments

Comments
 (0)