chore: Return error if the regex is invalid

This commit is contained in:
Baptiste Roux
2023-02-01 18:24:39 +01:00
parent fdafa3aa81
commit 100bac8f87

View File

@@ -28,7 +28,7 @@ fn find_repos(
let mut warnings = Vec::new(); let mut warnings = Vec::new();
let exlusion_regex: regex::Regex = regex::Regex::new(&exclusion_pattern.unwrap_or(r"^$")) let exlusion_regex: regex::Regex = regex::Regex::new(&exclusion_pattern.unwrap_or(r"^$"))
.unwrap_or_else(|_| regex::Regex::new(r"^$").unwrap()); .map_err(|e| format!("invalid regex: {e}"))?;
for path in tree::find_repo_paths(root)? { for path in tree::find_repo_paths(root)? {
if exclusion_pattern.is_some() && exlusion_regex.is_match(&path::path_as_string(&path)) { if exclusion_pattern.is_some() && exlusion_regex.is_match(&path::path_as_string(&path)) {
warnings.push(format!("[skipped] {}", &path::path_as_string(&path))); warnings.push(format!("[skipped] {}", &path::path_as_string(&path)));