Skip to content

Commit 1fabfc5

Browse files
committed
fix(error)!: Remove nom from ConfigError
Fixes #516
1 parent 35ba3bd commit 1fabfc5

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub enum ConfigError {
4646
NotFound(String),
4747

4848
/// Configuration path could not be parsed.
49-
PathParse(nom::error::ErrorKind),
49+
PathParse { cause: Box<dyn Error + Send + Sync> },
5050

5151
/// Configuration could not be parsed from file.
5252
FileParse {
@@ -187,7 +187,7 @@ impl fmt::Display for ConfigError {
187187
match *self {
188188
ConfigError::Frozen => write!(f, "configuration is frozen"),
189189

190-
ConfigError::PathParse(ref kind) => write!(f, "{}", kind.description()),
190+
ConfigError::PathParse { ref cause } => write!(f, "{cause}"),
191191

192192
ConfigError::Message(ref s) => write!(f, "{s}"),
193193

src/path/mod.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,29 @@ impl FromStr for Expression {
1717
type Err = ConfigError;
1818

1919
fn from_str(s: &str) -> Result<Self> {
20-
parser::from_str(s).map_err(ConfigError::PathParse)
20+
parser::from_str(s).map_err(|e| ConfigError::PathParse {
21+
cause: Box::new(ParseError::new(e)),
22+
})
2123
}
2224
}
2325

26+
#[derive(Debug)]
27+
struct ParseError(String);
28+
29+
impl ParseError {
30+
fn new(inner: nom::error::ErrorKind) -> Self {
31+
Self(inner.description().to_owned())
32+
}
33+
}
34+
35+
impl std::fmt::Display for ParseError {
36+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
37+
self.0.fmt(f)
38+
}
39+
}
40+
41+
impl std::error::Error for ParseError {}
42+
2443
fn sindex_to_uindex(index: isize, len: usize) -> usize {
2544
if index >= 0 {
2645
index as usize

0 commit comments

Comments
 (0)