Skip to content

Commit

Permalink
✨ Add warn in ResourceNameRegexpMatcher, use find_map in Identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
ShellWen committed Mar 9, 2024
1 parent 3e5e55e commit e9bc0e9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
8 changes: 1 addition & 7 deletions crates/core/src/identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,7 @@ pub(crate) trait Identifier {

impl Identifier for Vec<IdentifierEnum> {
fn identify(&self) -> Option<NativePointer> {
for identifier in self {
let ptr = identifier.identify();
if ptr.is_some() {
return ptr;
}
}
None
self.iter().find_map(|identifier| identifier.identify())
}
}

Expand Down
12 changes: 10 additions & 2 deletions crates/core/src/matcher.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use serde::Deserialize;
use tracing::warn;

use crate::source::Source;

Expand Down Expand Up @@ -42,7 +43,14 @@ pub struct ResourceNameRegexpMatcher {

impl SourceMatcher for ResourceNameRegexpMatcher {
fn matches(&self, source: &Source) -> bool {
let re = regex::Regex::new(&self.regexp).unwrap();
re.is_match(&source.resource_name)
let re = regex::Regex::new(&self.regexp);
match re {
Ok(re) => re.is_match(&source.resource_name),
Err(_) => {
warn!("Invalid regexp: {}", &self.regexp);
warn!("It will be ignored. Please check your config file");
false
}
}
}
}

0 comments on commit e9bc0e9

Please sign in to comment.