From 6b52db764198e1272d9199341c1bf09ecd635bb0 Mon Sep 17 00:00:00 2001 From: Andrew Langmeier Date: Sat, 29 Jul 2023 00:11:00 -0400 Subject: [PATCH] Fixes #2250, Zola Panics With a Non-Existent Project Root or Config Error instead --- src/main.rs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6f3fcdfeb7..4fbcda13f3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 {