Merge pull request #2902 from ehuss/fix-missing-format

Fix error message for config.get deserialization error
This commit is contained in:
Eric Huss 2025-10-25 23:52:46 +00:00 committed by GitHub
commit 860e8d109e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -204,7 +204,7 @@ impl Config {
value
.clone()
.try_into()
.with_context(|| "Failed to deserialize `{name}`")
.with_context(|| format!("Failed to deserialize `{name}`"))
})
.transpose()
}
@ -1147,4 +1147,18 @@ mod tests {
assert_eq!(json!(TextDirection::RightToLeft), json!("rtl"));
assert_eq!(json!(TextDirection::LeftToRight), json!("ltr"));
}
#[test]
fn get_deserialize_error() {
let src = r#"
[preprocessor.foo]
x = 123
"#;
let cfg = Config::from_str(src).unwrap();
let err = cfg.get::<String>("preprocessor.foo.x").unwrap_err();
assert_eq!(
err.to_string(),
"Failed to deserialize `preprocessor.foo.x`"
);
}
}