Skip to content

Commit

Permalink
Fixes getzola#2250, Zola Panics With a Non-Existent Project Root or C…
Browse files Browse the repository at this point in the history
…onfig

Error instead
  • Loading branch information
alangmeier-canold committed Jul 29, 2023
1 parent 695c17d commit 6b52db7
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,28 @@ mod messages;
mod prompt;

fn get_config_file_path(dir: &Path, config_path: &Path) -> (PathBuf, PathBuf) {
let root_dir = dir
.ancestors()
.find(|a| a.join(config_path).exists())
.unwrap_or_else(|| panic!("could not find directory containing config file"));
let root_dir = dir.ancestors().find(|a| a.join(config_path).exists()).unwrap_or_else(|| {
console::error("Could not find directory containing config file");
std::process::exit(1);
});

// if we got here we found root_dir so config file should exist so we can unwrap safely
let config_file = root_dir
.join(config_path)
.canonicalize()
.unwrap_or_else(|_| panic!("could not find directory containing config file"));
let config_file = root_dir.join(config_path).canonicalize().unwrap_or_else(|_| {
console::error("Could not find directory containing config file");
std::process::exit(1);
});

(root_dir.to_path_buf(), config_file)
}

fn main() {
let cli = Cli::parse();
let cli_dir: PathBuf = cli.root.canonicalize().unwrap_or_else(|_| {
panic!("Could not find canonical path of root dir: {}", cli.root.display())
console::error(&format!(
"Could not find canonical path of root dir: {}",
cli.root.display()
));
std::process::exit(1);
});

match cli.command {
Expand Down

0 comments on commit 6b52db7

Please sign in to comment.