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 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ repository.workspace = true
workspace = true

[dependencies]
serde_ignored = "0.1"
foundry-block-explorers = { workspace = true, features = ["foundry-compilers"] }
foundry-compilers = { workspace = true, features = ["svm-solc"] }

Expand Down
19 changes: 19 additions & 0 deletions crates/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ use std::{
str::FromStr,
};

use tracing::warn;

mod macros;

pub mod utils;
Expand Down Expand Up @@ -641,6 +643,23 @@ impl Config {
}

fn from_figment(figment: Figment) -> Result<Self, ExtractConfigError> {
let file_path = Path::new("foundry.toml");
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a good practice to not use hardcoded paths, a FILE_NAME const is already defined in this module.

if let Ok(raw) = fs::read_to_string(&file_path) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Clippy says there is a needless borrow here, so you can remove the & to pass the check.

let deserializer = toml::Deserializer::new(&raw);
let mut ignored = Vec::new();
let _: Result<Self, _> = serde_ignored::deserialize(deserializer, |path| {
ignored.push(path.to_string());
});

if !ignored.is_empty() {
warn!(
"Found unknown config keys in {}: {}",
file_path.display(),
Copy link
Contributor

Choose a reason for hiding this comment

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

cf remark about filename.

ignored.join(", ")
);
}
}

let mut config = figment.extract::<Self>().map_err(ExtractConfigError::new)?;
config.profile = figment.profile().clone();

Expand Down
Loading