From 67e13674f5aac693d617a879be2d7faa2f95c9c3 Mon Sep 17 00:00:00 2001 From: Kyohei Uto Date: Sat, 20 Jan 2024 07:28:19 +0900 Subject: [PATCH] Error handling for target path --- src/main.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index d3fd81b..aa76aff 100644 --- a/src/main.rs +++ b/src/main.rs @@ -48,13 +48,16 @@ fn main() -> Result<(), errors::FxError> { } _ => { if args[1].starts_with("--choosefiles=") { - let target_path = PathBuf::from(args[1].split('=').nth(1).unwrap()); - if let Err(e) = run::run( - std::env::current_dir().unwrap_or_else(|_| PathBuf::from(".")), - false, - Some(target_path), - ) { - eprintln!("{}", e); + if let Some(target_path) = args[1].split('=').nth(1) { + if let Err(e) = run::run( + std::env::current_dir().unwrap_or_else(|_| PathBuf::from(".")), + false, + Some(PathBuf::from(target_path)), + ) { + eprintln!("{}", e); + } + } else { + eprintln!("Cannot read target file path."); } } else if let Err(e) = run::run(PathBuf::from(&args[1]), false, None) { eprintln!("{}", e);