Skip to content

Commit e452060

Browse files
committed
Use the NotFound variant of the IO error
1 parent 83cd91c commit e452060

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/main.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,23 +91,22 @@ fn main() {
9191
println!("\n{WELCOME}\n");
9292
}
9393

94-
if !Path::new("info.toml").exists() {
95-
println!(
96-
"{} must be run from the rustlings directory",
97-
std::env::current_exe().unwrap().to_str().unwrap()
98-
);
99-
println!("Try `cd rustlings/`!");
100-
std::process::exit(1);
101-
}
102-
10394
if !rustc_exists() {
10495
println!("We cannot find `rustc`.");
10596
println!("Try running `rustc --version` to diagnose your problem.");
10697
println!("For instructions on how to install Rust, check the README.");
10798
std::process::exit(1);
10899
}
109100

110-
let info_file = fs::read_to_string("info.toml").unwrap();
101+
let info_file = fs::read_to_string("info.toml").unwrap_or_else(|e| {
102+
match e.kind() {
103+
io::ErrorKind::NotFound => println!(
104+
"The program must be run from the rustlings directory\nTry `cd rustlings/`!",
105+
),
106+
_ => println!("Failed to read the info.toml file: {e}"),
107+
}
108+
std::process::exit(1);
109+
});
111110
let exercises = toml_edit::de::from_str::<ExerciseList>(&info_file)
112111
.unwrap()
113112
.exercises;

0 commit comments

Comments
 (0)