warn on invalid fields in root of book.toml

This commit is contained in:
Gabor Szabo 2025-03-28 10:56:41 +03:00
parent a56cffeb4e
commit 1bc2ebd775

View file

@ -312,6 +312,8 @@ impl<'de> serde::Deserialize<'de> for Config {
return Ok(Config::from_legacy(raw));
}
warn_on_invalid_fields(&raw);
use serde::de::Error;
let mut table = match raw {
Value::Table(t) => t,
@ -376,6 +378,20 @@ fn parse_env(key: &str) -> Option<String> {
.map(|key| key.to_lowercase().replace("__", ".").replace('_', "-"))
}
fn warn_on_invalid_fields(table: &Value) {
let valid_items = ["book", "build", "rust", "output", "preprocessor"];
if let Some(table) = table.as_table() {
for item in table.keys() {
if !valid_items.contains(&item.as_str()) {
warn!("Invalid field {:?} in book.toml", &item);
}
}
} else {
warn!("Invalid format in book.toml");
}
}
fn is_legacy_format(table: &Value) -> bool {
let legacy_items = [
"title",