Skip to content

Commit b88c238

Browse files
committed
Give a more helpful error when a file is missing
Previously, this would just say "missing file". Now it shows the path of the file that was missing, which should make it easier to debug what went wrong.
1 parent 06f8653 commit b88c238

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)