Skip to content

Commit 4f698f8

Browse files
authored
Merge pull request #2622 from szabgab/warn-on-invalid-configuration-field
warn on invalid fields in the root of book.toml
2 parents b7a27d2 + 97f1948 commit 4f698f8

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/config.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,8 @@ impl<'de> serde::Deserialize<'de> for Config {
312312
return Ok(Config::from_legacy(raw));
313313
}
314314

315+
warn_on_invalid_fields(&raw);
316+
315317
use serde::de::Error;
316318
let mut table = match raw {
317319
Value::Table(t) => t,
@@ -376,6 +378,17 @@ fn parse_env(key: &str) -> Option<String> {
376378
.map(|key| key.to_lowercase().replace("__", ".").replace('_', "-"))
377379
}
378380

381+
fn warn_on_invalid_fields(table: &Value) {
382+
let valid_items = ["book", "build", "rust", "output", "preprocessor"];
383+
384+
let table = table.as_table().expect("root must be a table");
385+
for item in table.keys() {
386+
if !valid_items.contains(&item.as_str()) {
387+
warn!("Invalid field {:?} in book.toml", &item);
388+
}
389+
}
390+
}
391+
379392
fn is_legacy_format(table: &Value) -> bool {
380393
let legacy_items = [
381394
"title",

0 commit comments

Comments
 (0)