Skip to content

Commit

Permalink
Fixes #272 (#290)
Browse files Browse the repository at this point in the history
Co-authored-by: boyned//Kampfkarren <boynedmaster@gmail.com>
  • Loading branch information
soutenu and Kampfkarren authored Oct 11, 2021
1 parent 500e0cf commit 964fcc8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 29 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## Unreleased
### Fixed
- Fixed standard library error when missing files. [(#272)](https://github.com/Kampfkarren/selene/issues/272)
- Fixed display style option triggering `ArgumentConflict` when using quiet option. [(#288)](https://github.com/Kampfkarren/selene/issues/288)
- `bad_string_escape` now correctly handles escapes of the shape `\1a` (one or two numbers followed by a hex digit). (#292)[https://github.com/Kampfkarren/selene/issues/292]

Expand Down
71 changes: 42 additions & 29 deletions selene/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(&current_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<PathBuf> = 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(&current_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);
}
}
}
};

Expand Down

0 comments on commit 964fcc8

Please sign in to comment.