Added error handling

This commit is contained in:
SalOne22 2023-07-12 11:00:55 +02:00
parent c411ab30d4
commit e87920b736

View file

@ -310,8 +310,12 @@ Heuristic filter selection strategies:
matches matches
.get_many::<PathBuf>("files") .get_many::<PathBuf>("files")
.unwrap() .unwrap()
.cloned() .flat_map(|path| {
.flat_map(apply_glob_pattern) apply_glob_pattern(path).unwrap_or_else(|e| {
warn!("{path:?}: {e}");
vec![]
})
})
.collect(), .collect(),
#[cfg(not(windows))] #[cfg(not(windows))]
matches matches
@ -392,13 +396,13 @@ fn collect_files(
} }
#[cfg(windows)] #[cfg(windows)]
fn apply_glob_pattern(path: PathBuf) -> Vec<PathBuf> { fn apply_glob_pattern(path: &std::path::Path) -> Result<Vec<PathBuf>, String> {
let input_path = path.to_str().unwrap(); let input_path = path.to_str().ok_or("Failed to read path.".to_string())?;
glob::glob(input_path) Ok(glob::glob(input_path)
.expect("Failed to read glob pattern") .map_err(|e| e.to_string())?
.map(|path| path.unwrap()) .flatten()
.collect() .collect())
} }
fn parse_opts_into_struct( fn parse_opts_into_struct(