summaryrefslogtreecommitdiff
path: root/src/exercise.rs
diff options
context:
space:
mode:
authorjyn <github@jyn.dev>2023-09-25 03:36:43 -0400
committerjyn <github@jyn.dev>2023-09-25 03:41:13 -0400
commitb88c23897f27ff5aa7d700f0bc16a289068445d5 (patch)
treeea09719f7472db27504b7dfbc2ecc0f0d0a54d4d /src/exercise.rs
parent06f865307f0c92080d88d747bccac896e29e1baf (diff)
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.
Diffstat (limited to 'src/exercise.rs')
-rw-r--r--src/exercise.rs17
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
};