summaryrefslogtreecommitdiffstats
path: root/src/error.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/error.rs')
-rw-r--r--src/error.rs46
1 files changed, 12 insertions, 34 deletions
diff --git a/src/error.rs b/src/error.rs
index d7beeaf..b6730e3 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -51,7 +51,7 @@ pub enum ConfigError {
/// The captured error from attempting to parse the file in its desired format.
/// This is the actual error object from the library used for the parsing.
- cause: Box<Error + Send + Sync>,
+ cause: Box<dyn Error + Send + Sync>,
},
/// Value could not be converted into the requested type.
@@ -76,7 +76,7 @@ pub enum ConfigError {
Message(String),
/// Unadorned error from a foreign origin.
- Foreign(Box<Error + Send + Sync>),
+ Foreign(Box<dyn Error + Send + Sync>),
}
impl ConfigError {
@@ -88,9 +88,9 @@ impl ConfigError {
expected: &'static str,
) -> Self {
ConfigError::Type {
- origin: origin,
- unexpected: unexpected,
- expected: expected,
+ origin,
+ unexpected,
+ expected,
key: None,
}
}
@@ -105,9 +105,9 @@ impl ConfigError {
expected,
..
} => ConfigError::Type {
- origin: origin,
- unexpected: unexpected,
- expected: expected,
+ origin,
+ unexpected,
+ expected,
key: Some(key.into()),
},
@@ -166,7 +166,9 @@ impl fmt::Debug for ConfigError {
impl fmt::Display for ConfigError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
- ConfigError::Frozen | ConfigError::PathParse(_) => write!(f, "{}", self.description()),
+ ConfigError::Frozen => write!(f, "configuration is frozen"),
+
+ ConfigError::PathParse(ref kind) => write!(f, "{}", kind.description()),
ConfigError::Message(ref s) => write!(f, "{}", s),
@@ -208,31 +210,7 @@ impl fmt::Display for ConfigError {
}
}
-impl Error for ConfigError {
- fn description(&self) -> &str {
- match *self {
- ConfigError::Frozen => "configuration is frozen",
- ConfigError::NotFound(_) => "configuration property not found",
- ConfigError::Type { .. } => "invalid type",
- ConfigError::Foreign(ref cause) | ConfigError::FileParse { ref cause, .. } => {
- cause.description()
- }
- ConfigError::PathParse(ref kind) => kind.description(),
-
- _ => "configuration error",
- }
- }
-
- fn cause(&self) -> Option<&Error> {
- match *self {
- ConfigError::Foreign(ref cause) | ConfigError::FileParse { ref cause, .. } => {
- Some(cause.as_ref())
- }
-
- _ => None,
- }
- }
-}
+impl Error for ConfigError { }
impl de::Error for ConfigError {
fn custom<T: fmt::Display>(msg: T) -> Self {