From 982d412c1bb543b11af8bcd4c5ff5dd445b8fbff Mon Sep 17 00:00:00 2001 From: Oscar Trujillo Date: Thu, 2 Sep 2021 05:01:53 -0400 Subject: [PATCH 1/2] Fixes #272 --- selene/src/main.rs | 71 +++++++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 29 deletions(-) diff --git a/selene/src/main.rs b/selene/src/main.rs index f2bd29a8..27b78929 100644 --- a/selene/src/main.rs +++ b/selene/src/main.rs @@ -2,7 +2,7 @@ use std::{ ffi::OsString, fmt, fs, io::{self, Read, Write}, - path::Path, + path::{Path, PathBuf}, sync::{ atomic::{AtomicUsize, Ordering}, Arc, RwLock, @@ -403,42 +403,55 @@ fn start(matches: opts::Options) { std::process::exit(1); } - Err(error) => { + Err(_) => { if cfg!(feature = "roblox") && config.std.split('+').any(|name| name == "roblox") { - eprint!("`std = \"roblox\"`, but there is no roblox.toml in this directory. "); - eprintln!("We are automatically generating one for you now!"); - - eprint!("By the way, you can do this manually in the future if you need "); - eprint!("to use new Roblox features with: "); - eprintln!("`selene generate-roblox-std`."); - - match generate_roblox_std(false) { - Ok(_) => { - match StandardLibrary::from_config_name(&config.std, Some(¤t_dir)) { - Ok(Some(library)) => library, - - // This is technically reachable if you edit your config while it is generating. - Ok(None) => { - error!("Standard library was empty after generating roblox standard library, did you edit your config while running selene?"); - std::process::exit(1); - } + if !Path::new("roblox.toml").exists() { + eprint!("Roblox standard library could not be found in this directory. "); + eprintln!("We are automatically generating one for you now!"); - Err(error) => { - error!("Even after generating the `roblox` standard library, we couldn't retrieve the standard library: {}", error); - std::process::exit(1); - } - } - } + eprint!("By the way, you can do this manually in the future if you need "); + eprint!("to use new Roblox features with: "); + eprintln!("`selene generate-roblox-std`."); - Err(err) => { - error!("Could not create roblox standard library: {}", err); + if let Err(error) = generate_roblox_std(false) { + error!("Could not create roblox standard library: {}", error); std::process::exit(1); } } - } else { - error!("Could not retrieve standard library: {}", error); + } + + let missing_files: Vec = config.std + .split('+') + .map(|name| format!("{}.toml", name)) + .map(|name| PathBuf::from(&name)) + .filter(|path| !path.exists()) + .collect(); + + if !missing_files.is_empty() { + eprintln!("`std = \"{}\"`, but some files could not be found:", config.std); + + for path in missing_files { + eprintln!(" `{}`", path.display()); + } + + error!("Could not find all standard library files"); std::process::exit(1); } + + match StandardLibrary::from_config_name(&config.std, Some(¤t_dir)) { + Ok(Some(library)) => library, + + // This is technically reachable if you edit your config while it is generating. + Ok(None) => { + error!("Standard library was empty, did you edit your config while running selene?"); + std::process::exit(1); + } + + Err(error) => { + error!("Could not retrieve standard library: {}", error); + std::process::exit(1); + } + } } }; From 3a7552dcad8096487d38c12c3ca28c88b07e9dbe Mon Sep 17 00:00:00 2001 From: Oscar Trujillo Date: Thu, 2 Sep 2021 05:06:47 -0400 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c02e3de4..7b6505a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased +### Fixed +- Fixed standard library error when missing files. [(#272)](https://github.com/Kampfkarren/selene/issues/272) + ## [0.14.0] - 2021-07-07 ### Added - Added `task` library to Roblox standard library.