Skip to content

Deny all unknown config fields #2787

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 12, 2025
Merged

Conversation

ehuss
Copy link
Contributor

@ehuss ehuss commented Aug 12, 2025

This changes it so that it is an error if there is ever an unknown configuration field. This is intended to help avoid things like typos, or using an outdated version of mdbook. Although it is possible that new fields could potentially safely be ignored, setting up a warning system is a bit more of a hassle. I don't think mdbook needs to have the same kind of multi-version support as something like cargo does. However, if this ends up being too much of a pain point, we can try to add a warning system instead.

There are a variety of changes here:

  • The top-level config namespace is now closed so that it only accepts the keys defined in Config.
  • All config tables now reject unknown fields.
  • Added Config::outputs and Config::preprocessors for convenience to access the entire output and preprocessor tables.
  • Moved the unit-tests that were setting environment variables to the testsuite where it launches a process instead.

Closes #1595

@rustbot rustbot added the S-waiting-on-review Status: waiting on a review label Aug 12, 2025
@ehuss ehuss added the Breaking Change This would require a SemVer breaking change label Aug 12, 2025
This changes it so that it is an error if there is ever an unknown
configuration field. This is intended to help avoid things like typos,
or using an outdated version of mdbook. Although it is possible that new
fields could potentially safely be ignored, setting up a warning system
is a bit more of a hassle. I don't think mdbook needs to have the same
kind of multi-version support as something like cargo does. However, if
this ends up being too much of a pain point, we can try to add a warning
system instead.

There are a variety of changes here:

- The top-level config namespace is now closed so that it only accepts
  the keys defined in `Config`.
- All config tables now reject unknown fields.
- Added `Config::outputs` and `Config::preprocessors` for convenience
  to access the entire `output` and `preprocessor` tables.
- Moved the unit-tests that were setting environment variables to the
  testsuite where it launches a process instead.

Closes rust-lang#1595
@ehuss ehuss force-pushed the deny-unknown-fields branch from e5f86ba to d290727 Compare August 12, 2025 22:14
@ehuss
Copy link
Contributor Author

ehuss commented Aug 12, 2025

@szabgab FYI, I decided to go ahead with this for 0.5 to just error on these fields.

@ehuss ehuss enabled auto-merge August 12, 2025 22:18
@ehuss ehuss added this pull request to the merge queue Aug 12, 2025
Merged via the queue into rust-lang:master with commit 79e9ae4 Aug 12, 2025
14 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: waiting on a review label Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Breaking Change This would require a SemVer breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Warn on unknown configuration settings
2 participants