From e87920b736be00f1d562a125b6c4a78872a75b09 Mon Sep 17 00:00:00 2001 From: SalOne22 <111443297+SalOne22@users.noreply.github.com> Date: Wed, 12 Jul 2023 11:00:55 +0200 Subject: [PATCH] Added error handling --- src/main.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index d8d14e9e..0dad90c4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -310,8 +310,12 @@ Heuristic filter selection strategies: matches .get_many::("files") .unwrap() - .cloned() - .flat_map(apply_glob_pattern) + .flat_map(|path| { + apply_glob_pattern(path).unwrap_or_else(|e| { + warn!("{path:?}: {e}"); + vec![] + }) + }) .collect(), #[cfg(not(windows))] matches @@ -392,13 +396,13 @@ fn collect_files( } #[cfg(windows)] -fn apply_glob_pattern(path: PathBuf) -> Vec { - let input_path = path.to_str().unwrap(); +fn apply_glob_pattern(path: &std::path::Path) -> Result, String> { + let input_path = path.to_str().ok_or("Failed to read path.".to_string())?; - glob::glob(input_path) - .expect("Failed to read glob pattern") - .map(|path| path.unwrap()) - .collect() + Ok(glob::glob(input_path) + .map_err(|e| e.to_string())? + .flatten() + .collect()) } fn parse_opts_into_struct(