summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authormo8it <mo8it@proton.me>2024-03-25 02:41:45 +0100
committermo8it <mo8it@proton.me>2024-03-25 02:41:45 +0100
commite4520602f52935ff310534afc65160bcc5796a97 (patch)
tree69ec295b2e319bb52de0e20e34446fe9b3879e02 /src/main.rs
parent83cd91ccca22e36ed94e03cc622a88ef45e6da10 (diff)
Use the NotFound variant of the IO error
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/main.rs b/src/main.rs
index 8e0029d..d6542aa 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -91,15 +91,6 @@ fn main() {
println!("\n{WELCOME}\n");
}
- if !Path::new("info.toml").exists() {
- println!(
- "{} must be run from the rustlings directory",
- std::env::current_exe().unwrap().to_str().unwrap()
- );
- println!("Try `cd rustlings/`!");
- std::process::exit(1);
- }
-
if !rustc_exists() {
println!("We cannot find `rustc`.");
println!("Try running `rustc --version` to diagnose your problem.");
@@ -107,7 +98,15 @@ fn main() {
std::process::exit(1);
}
- let info_file = fs::read_to_string("info.toml").unwrap();
+ let info_file = fs::read_to_string("info.toml").unwrap_or_else(|e| {
+ match e.kind() {
+ io::ErrorKind::NotFound => println!(
+ "The program must be run from the rustlings directory\nTry `cd rustlings/`!",
+ ),
+ _ => println!("Failed to read the info.toml file: {e}"),
+ }
+ std::process::exit(1);
+ });
let exercises = toml_edit::de::from_str::<ExerciseList>(&info_file)
.unwrap()
.exercises;