mirror of
https://github.com/OMGeeky/confique.git
synced 2026-01-07 20:17:02 +01:00
Change parse_env error type from Debug to impl std::error::Error
This is the more appropriate trait I think and should work well for most real world use cases.
This commit is contained in:
12
src/error.rs
12
src/error.rs
@@ -50,6 +50,13 @@ pub(crate) enum ErrorInner {
|
||||
msg: String,
|
||||
},
|
||||
|
||||
/// When a custom `parse_env` function fails.
|
||||
EnvParseError {
|
||||
field: String,
|
||||
key: String,
|
||||
err: Box<dyn std::error::Error + Send + Sync>,
|
||||
},
|
||||
|
||||
/// Returned by the [`Source`] impls for `Path` and `PathBuf` if the file
|
||||
/// extension is not supported by confique or if the corresponding Cargo
|
||||
/// feature of confique was not enabled.
|
||||
@@ -71,6 +78,7 @@ impl std::error::Error for Error {
|
||||
ErrorInner::MissingValue(_) => None,
|
||||
ErrorInner::EnvNotUnicode { .. } => None,
|
||||
ErrorInner::EnvDeserialization { .. } => None,
|
||||
ErrorInner::EnvParseError { err, .. } => Some(&**err),
|
||||
ErrorInner::UnsupportedFileFormat { .. } => None,
|
||||
ErrorInner::MissingFileExtension { .. } => None,
|
||||
ErrorInner::MissingRequiredFile { .. } => None,
|
||||
@@ -107,6 +115,10 @@ impl fmt::Display for Error {
|
||||
std::write!(f, "failed to deserialize value `{field}` from \
|
||||
environment variable `{key}`: {msg}")
|
||||
}
|
||||
ErrorInner::EnvParseError { field, key, err } => {
|
||||
std::write!(f, "failed to parse environment variable `{key}` into \
|
||||
field `{field}`: {err}")
|
||||
}
|
||||
ErrorInner::UnsupportedFileFormat { path } => {
|
||||
std::write!(f,
|
||||
"unknown configuration file format/extension: '{}'",
|
||||
|
||||
Reference in New Issue
Block a user