From b00ae4261bfb2d613583d51a1ce877b157c8740b Mon Sep 17 00:00:00 2001 From: Ever Date: Fri, 7 Apr 2023 03:28:20 +0800 Subject: [PATCH] print error message when no config file found (#2168) fixed #2195 --- src/main.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6f3fcdfeb7..983f7b2aa7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ use std::path::{Path, PathBuf}; use std::time::Instant; use cli::{Cli, Command}; +use errors::anyhow; use utils::net::{get_available_port, port_is_available}; use clap::{CommandFactory, Parser}; @@ -13,10 +14,17 @@ 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(|| { + messages::unravel_errors( + "", + &anyhow!( + "{} not found in current directory or ancestors, current_dir is {}", + config_path.display(), + dir.display() + ), + ); + 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