1
0
mirror of https://github.com/rust-lang/rustlings.git synced 2024-11-08 09:09:17 +01:00

Merge pull request #1690 from jyn514/error-handling

Give a more helpful error when a file is missing
This commit is contained in:
liv 2023-09-26 11:02:05 +02:00 committed by GitHub
commit da3d55ba03
Signed by: GitHub
GPG Key ID: 4AEE18F83AFDEB23

@ -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
};