From 08d9fddfc93cadb332dd5e450e52b8382c0852f2 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sat, 25 Oct 2025 16:45:48 -0700 Subject: [PATCH 1/2] Add a test for config.get deserialization error --- crates/mdbook-core/src/config.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/mdbook-core/src/config.rs b/crates/mdbook-core/src/config.rs index 6f2a8a7a03..301e545640 100644 --- a/crates/mdbook-core/src/config.rs +++ b/crates/mdbook-core/src/config.rs @@ -1147,4 +1147,15 @@ 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::("preprocessor.foo.x").unwrap_err(); + assert_eq!(err.to_string(), "Failed to deserialize `{name}`"); + } } From adcbd117da22567c81cb2937faacc42ec45a2750 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sat, 25 Oct 2025 16:46:51 -0700 Subject: [PATCH 2/2] Fix error message for config.get deserialization error The error message for a deserialization failure was missing a call to `format!`. --- crates/mdbook-core/src/config.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/mdbook-core/src/config.rs b/crates/mdbook-core/src/config.rs index 301e545640..760af9922e 100644 --- a/crates/mdbook-core/src/config.rs +++ b/crates/mdbook-core/src/config.rs @@ -204,7 +204,7 @@ impl Config { value .clone() .try_into() - .with_context(|| "Failed to deserialize `{name}`") + .with_context(|| format!("Failed to deserialize `{name}`")) }) .transpose() } @@ -1156,6 +1156,9 @@ mod tests { "#; let cfg = Config::from_str(src).unwrap(); let err = cfg.get::("preprocessor.foo.x").unwrap_err(); - assert_eq!(err.to_string(), "Failed to deserialize `{name}`"); + assert_eq!( + err.to_string(), + "Failed to deserialize `preprocessor.foo.x`" + ); } }