Skip to content

Commit

Permalink
Forward regex parser errors to enable understandin their reason.
Browse files Browse the repository at this point in the history
  • Loading branch information
adamreichold committed Dec 22, 2023
1 parent 9c75942 commit ff056a9
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/query/regex_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl RegexQuery {
/// Creates a new RegexQuery from a given pattern
pub fn from_pattern(regex_pattern: &str, field: Field) -> crate::Result<Self> {
let regex = Regex::new(regex_pattern)
.map_err(|_| TantivyError::InvalidArgument(regex_pattern.to_string()))?;
.map_err(|err| TantivyError::InvalidArgument(format!("RegexQueryError: {err}")))?;
Ok(RegexQuery::from_regex(regex, field))
}

Expand Down Expand Up @@ -176,4 +176,16 @@ mod test {
verify_regex_query(matching_one, matching_zero, reader);
Ok(())
}

#[test]
pub fn test_pattern_error() {
let (_reader, field) = build_test_index().unwrap();

match RegexQuery::from_pattern(r"(foo", field) {
Err(crate::TantivyError::InvalidArgument(msg)) => {
assert!(msg.contains("error: unclosed group"))
}
res => panic!("unexpected result: {:?}", res),
}
}
}

0 comments on commit ff056a9

Please sign in to comment.