mirror of
https://github.com/notohh/rustlings.git
synced 2024-11-22 22:02:22 -05:00
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.
This commit is contained in:
parent
06f865307f
commit
b88c23897f
1 changed files with 12 additions and 5 deletions
|
@ -201,14 +201,21 @@ path = "{}.rs""#,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn state(&self) -> State {
|
pub fn state(&self) -> State {
|
||||||
let mut source_file =
|
let mut source_file = File::open(&self.path).unwrap_or_else(|e| {
|
||||||
File::open(&self.path).expect("We were unable to open the exercise file!");
|
panic!(
|
||||||
|
"We were unable to open the exercise file {}! {e}",
|
||||||
|
self.path.display()
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
let source = {
|
let source = {
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
source_file
|
source_file.read_to_string(&mut s).unwrap_or_else(|e| {
|
||||||
.read_to_string(&mut s)
|
panic!(
|
||||||
.expect("We were unable to read the exercise file!");
|
"We were unable to read the exercise file {}! {e}",
|
||||||
|
self.path.display()
|
||||||
|
)
|
||||||
|
});
|
||||||
s
|
s
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue