Skip to content

feat(config): warn on unknown config keys in foundry.toml #10621

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

zarkk01
Copy link
Contributor

@zarkk01 zarkk01 commented May 24, 2025

Motivation

closes #10550

Right now, if a user makes a typo or adds a deprecated field in their local foundry.toml, Figment/Serde simply ignores it and the user never knows something went unused. That can lead to confusion or misconfiguration.

Solution

Before Figment does .extract() into the Config struct, we read foundry.toml as raw TOML, run it through [serde_ignored] to collect any unused/unknown keys, and if any are found we log a warn! listing them. This is non-breaking (we still load all the valid settings) and only affects root keys for now.

For now, could I have some feedback on the implementation?

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

Copy link
Contributor

@mablr mablr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've given you a little feedback 👍

I think it might be nice to implement this verification as a separate helper function.

@grandizzy
Copy link
Collaborator

@zarkk01 this would be really good to have, wonder if you have time time to wrap up the work (accommodate comments and test to check warnings are emitted). thank you!

@zarkk01
Copy link
Contributor Author

zarkk01 commented Jun 5, 2025

@zarkk01 this would be really good to have, wonder if you have time time to wrap up the work (accommodate comments and test to check warnings are emitted). thank you!

Yes, I will wrap it up until the end of the week! :)

@zarkk01 zarkk01 requested a review from mablr June 8, 2025 10:35
Copy link
Collaborator

@grandizzy grandizzy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you, left some comments re current impl


// if we found any, log a single warning with a list
if !ignored.is_empty() {
warn!("Found unknown config keys in {}: {}", Self::FILE_NAME, ignored.join(", "));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should use sh_warn and output message. We already have collect_warnings so should use that one

pub fn collect_warnings(&self) -> Result<Vec<Warning>, Error> {

Would be great to address also the inline config, that is #5371


#[traced_test]
#[test]
fn warn_unknown_keys_logs_warning_for_unknown_keys() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are good but would be great to have an e2e test too where we run forge for a project with unknown config keys defined in foundry.toml and inline and we assert proper warnings displayed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

Warn on unknown config keys
3 participants