Skip to content

Commit 860e8d1

Browse files
authored
Merge pull request #2902 from ehuss/fix-missing-format
Fix error message for config.get deserialization error
2 parents 118c109 + adcbd11 commit 860e8d1

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

crates/mdbook-core/src/config.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ impl Config {
204204
value
205205
.clone()
206206
.try_into()
207-
.with_context(|| "Failed to deserialize `{name}`")
207+
.with_context(|| format!("Failed to deserialize `{name}`"))
208208
})
209209
.transpose()
210210
}
@@ -1147,4 +1147,18 @@ mod tests {
11471147
assert_eq!(json!(TextDirection::RightToLeft), json!("rtl"));
11481148
assert_eq!(json!(TextDirection::LeftToRight), json!("ltr"));
11491149
}
1150+
1151+
#[test]
1152+
fn get_deserialize_error() {
1153+
let src = r#"
1154+
[preprocessor.foo]
1155+
x = 123
1156+
"#;
1157+
let cfg = Config::from_str(src).unwrap();
1158+
let err = cfg.get::<String>("preprocessor.foo.x").unwrap_err();
1159+
assert_eq!(
1160+
err.to_string(),
1161+
"Failed to deserialize `preprocessor.foo.x`"
1162+
);
1163+
}
11501164
}

0 commit comments

Comments
 (0)