From 185377775aeeba57f91d6b40a8a599e840db1e90 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 6 May 2022 09:42:14 +0300 Subject: refactor: replace SubplotError::RegexError with a simpler one SubplotError::RegexError was a struct variant in the enum. Replace it with a more usual variant with the regex::Error as a source field, for better error messaging. Sponsored-by: author --- src/bindings.rs | 3 ++- src/error.rs | 8 ++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/bindings.rs b/src/bindings.rs index a6f96ca..5db63c9 100644 --- a/src/bindings.rs +++ b/src/bindings.rs @@ -171,7 +171,8 @@ impl Binding { ) -> Result { let regex = RegexBuilder::new(&format!("^{}$", pattern)) .case_insensitive(!case_sensitive) - .build()?; + .build() + .map_err(|err| SubplotError::Regex(pattern.to_string(), err))?; // For every named capture, ensure we have a known type for it. // If the type is missing from the map, we default to `text` which is // the .* pattern diff --git a/src/error.rs b/src/error.rs index 5286410..8fdaeee 100644 --- a/src/error.rs +++ b/src/error.rs @@ -291,12 +291,8 @@ pub enum SubplotError { /// /// Subplot uses regular expressions. This is a generic wrapper for /// any kinds of errors related to that. - #[error(transparent)] - RegexError { - /// The wrapped error. - #[from] - source: regex::Error, - }, + #[error("Failed to compile regular expression: {0:?}")] + Regex(String, #[source] regex::Error), /// JSON error /// -- cgit v1.2.1