Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ impl fmt::Display for ConfigError {
ConfigError::Foreign(ref cause) => write!(f, "{cause}"),

ConfigError::NotFound(ref key) => {
write!(f, "configuration property {key:?} not found")
write!(f, "missing configuration field {key:?}")
}

ConfigError::Type {
Expand Down Expand Up @@ -289,6 +289,10 @@ impl de::Error for ConfigError {
fn custom<T: fmt::Display>(msg: T) -> Self {
Self::Message(msg.to_string())
}

fn missing_field(field: &'static str) -> Self {
Self::NotFound(field.into())
}
}

impl ser::Error for ConfigError {
Expand Down
12 changes: 6 additions & 6 deletions tests/testsuite/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn test_path_index_bounds() {
assert!(res.is_err());
assert_data_eq!(
res.unwrap_err().to_string(),
str![[r#"configuration property "arr[2]" not found"#]]
str![[r#"missing configuration field "arr[2]""#]]
);
}

Expand All @@ -45,7 +45,7 @@ fn test_path_index_negative_bounds() {
assert!(res.is_err());
assert_data_eq!(
res.unwrap_err().to_string(),
str![[r#"configuration property "arr[-1]" not found"#]]
str![[r#"missing configuration field "arr[-1]""#]]
);
}

Expand Down Expand Up @@ -158,7 +158,7 @@ fn test_get_missing_field() {
let res = c.get::<InnerSettings>("inner");
assert_data_eq!(
res.unwrap_err().to_string(),
str!["missing field `value2` for key `inner`"]
str![[r#"missing configuration field "value2" for key `inner`"#]]
);
}

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

Expand Down Expand Up @@ -436,7 +436,7 @@ fn test_deserialize_missing_field() {
let res = c.try_deserialize::<Settings>();
assert_data_eq!(
res.unwrap_err().to_string(),
str!["missing field `value2` for key `inner`"]
str![[r#"missing configuration field "inner.value2""#]]
);
}

Expand Down Expand Up @@ -468,6 +468,6 @@ fn test_deserialize_missing_field_file() {
let res = c.try_deserialize::<Settings>();
assert_data_eq!(
res.unwrap_err().to_string(),
str!["missing field `value2` for key `inner`"]
str![[r#"missing configuration field "inner.value2""#]]
);
}
2 changes: 1 addition & 1 deletion tests/testsuite/file_corn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ fn test_override_uppercase_value_for_struct() {
);
}
Err(e) => {
if e.to_string().contains("missing field `FOO`") {
if matches!(e, config::ConfigError::NotFound(_)) {
assert_eq!(
lower_settings.foo,
"I HAVE BEEN OVERRIDDEN_WITH_UPPER_CASE".to_owned()
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/file_ini.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ rating = 4.5
);
}
Err(e) => {
if e.to_string().contains("missing field `FOO`") {
if matches!(e, config::ConfigError::NotFound(_)) {
assert_eq!(
lower_settings.foo,
"I HAVE BEEN OVERRIDDEN_WITH_UPPER_CASE".to_owned()
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/file_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ fn test_override_uppercase_value_for_struct() {
);
}
Err(e) => {
if e.to_string().contains("missing field `FOO`") {
if matches!(e, config::ConfigError::NotFound(_)) {
println!("triggered error {e:?}");
assert_eq!(
lower_settings.foo,
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/file_json5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ fn test_override_uppercase_value_for_struct() {
);
}
Err(e) => {
if e.to_string().contains("missing field `FOO`") {
if matches!(e, config::ConfigError::NotFound(_)) {
assert_eq!(
lower_settings.foo,
"I HAVE BEEN OVERRIDDEN_WITH_UPPER_CASE".to_owned()
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/file_ron.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ fn test_override_uppercase_value_for_struct() {
);
}
Err(e) => {
if e.to_string().contains("missing field `FOO`") {
if matches!(e, config::ConfigError::NotFound(_)) {
assert_eq!(
lower_settings.foo,
"I HAVE BEEN OVERRIDDEN_WITH_UPPER_CASE".to_owned()
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/file_toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ down = 1
);
}
Err(e) => {
if e.to_string().contains("missing field `FOO`") {
if matches!(e, config::ConfigError::NotFound(_)) {
assert_eq!(
lower_settings.foo,
"I HAVE BEEN OVERRIDDEN_WITH_UPPER_CASE".to_owned()
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/file_yaml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ bar: I am bar
);
}
Err(e) => {
if e.to_string().contains("missing field `FOO`") {
if matches!(e, config::ConfigError::NotFound(_)) {
println!("triggered error {e:?}");
assert_eq!(
lower_settings.foo,
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn test_not_found() {
assert!(res.is_err());
assert_data_eq!(
res.unwrap_err().to_string(),
str![[r#"configuration property "not_found" not found"#]]
str![[r#"missing configuration field "not_found""#]]
);
}

Expand Down