Skip to content

Commit 9fc4a83

Browse files
committed
Be nicer when rustlings isn't run from the right directory.
Before, rustlings would panic if it wasn't in the right directory. It took me a minute to figure out why, and this wasn't my first intro to Rust. It would probably help new users if they saw a helpful message instead of a stack trace.
1 parent 8f9d7ce commit 9fc4a83

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/main.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use notify::DebouncedEvent;
55
use notify::{RecommendedWatcher, RecursiveMode, Watcher};
66
use std::ffi::OsStr;
77
use std::io::BufRead;
8+
use std::path::Path;
89
use std::sync::mpsc::channel;
910
use std::time::Duration;
1011
use syntect::easy::HighlightFile;
@@ -47,6 +48,14 @@ fn main() {
4748
println!();
4849
}
4950

51+
if !Path::new("info.toml").exists() {
52+
println!(
53+
"{} must be run from the rustlings directory",
54+
std::env::current_exe().unwrap().to_str().unwrap()
55+
);
56+
std::process::exit(1);
57+
}
58+
5059
if let Some(matches) = matches.subcommand_matches("run") {
5160
run(matches.clone()).unwrap();
5261
}

0 commit comments

Comments
 (0)