Skip to content

Commit 22dccae

Browse files
committed
feat: Improve error from try_deserialize
1 parent 26fa590 commit 22dccae

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/error.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,10 @@ impl de::Error for ConfigError {
289289
fn custom<T: fmt::Display>(msg: T) -> Self {
290290
Self::Message(msg.to_string())
291291
}
292+
293+
fn missing_field(field: &'static str) -> Self {
294+
Self::NotFound(field.into())
295+
}
292296
}
293297

294298
impl ser::Error for ConfigError {

tests/testsuite/errors.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ fn test_get_missing_field() {
158158
let res = c.get::<InnerSettings>("inner");
159159
assert_data_eq!(
160160
res.unwrap_err().to_string(),
161-
str!["missing field `value2` for key `inner`"]
161+
str![[r#"missing configuration field "value2" for key `inner`"#]]
162162
);
163163
}
164164

@@ -184,7 +184,7 @@ fn test_get_missing_field_file() {
184184
let res = c.get::<InnerSettings>("inner");
185185
assert_data_eq!(
186186
res.unwrap_err().to_string(),
187-
str!["missing field `value2` for key `inner`"]
187+
str![[r#"missing configuration field "value2" for key `inner`"#]]
188188
);
189189
}
190190

@@ -468,6 +468,6 @@ fn test_deserialize_missing_field_file() {
468468
let res = c.try_deserialize::<Settings>();
469469
assert_data_eq!(
470470
res.unwrap_err().to_string(),
471-
str!["missing field `value2` for key `inner`"]
471+
str![[r#"missing configuration field "inner.value2""#]]
472472
);
473473
}

0 commit comments

Comments
 (0)