mirror of
https://github.com/OMGeeky/confique.git
synced 2026-01-06 19:49:38 +01:00
Fix using env with deserialize_with
Fixes #2 I simply forgot to use the `deserialize_with` attribute for the env deserialization. The previous code was somewhat weirdly coded in that we would always deserialize `Option<T>` (as it's a partial type) and the "env variable not present" info would travel through the deserializer to the `Option<T> as Deserialize` impl. Now it's more straight forward.
This commit is contained in:
15
src/error.rs
15
src/error.rs
@@ -34,6 +34,12 @@ pub(crate) enum ErrorInner {
|
||||
err: Box<dyn std::error::Error + Send + Sync>,
|
||||
},
|
||||
|
||||
/// When the env variable `key` is not Unicode.
|
||||
EnvNotUnicode {
|
||||
field: String,
|
||||
key: String,
|
||||
},
|
||||
|
||||
/// When deserialization via `env` fails. The string is what is passed to
|
||||
/// `serde::de::Error::custom`.
|
||||
EnvDeserialization {
|
||||
@@ -72,6 +78,7 @@ impl std::error::Error for Error {
|
||||
#[cfg(any(feature = "toml", feature = "yaml"))]
|
||||
ErrorInner::Deserialization { err, .. } => Some(&**err),
|
||||
ErrorInner::MissingValue(_) => None,
|
||||
ErrorInner::EnvNotUnicode { .. } => None,
|
||||
ErrorInner::EnvDeserialization { .. } => None,
|
||||
#[cfg(any(feature = "toml", feature = "yaml"))]
|
||||
ErrorInner::UnsupportedFileFormat { .. } => None,
|
||||
@@ -108,6 +115,14 @@ impl fmt::Display for Error {
|
||||
ErrorInner::Deserialization { source: None, .. } => {
|
||||
std::write!(f, "failed to deserialize configuration")
|
||||
}
|
||||
ErrorInner::EnvNotUnicode { field, key } => {
|
||||
std::write!(f,
|
||||
"failed to load value `{}` from environment variable `{}`: \
|
||||
value is not valid unicode",
|
||||
field,
|
||||
key,
|
||||
)
|
||||
}
|
||||
ErrorInner::EnvDeserialization { field, key, msg } => {
|
||||
std::write!(f,
|
||||
"failed to deserialize value `{}` from environment variable `{}`: {}",
|
||||
|
||||
Reference in New Issue
Block a user