Skip to content

Commit

Permalink
fix: only warn if config properties are not found (#2472)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx authored Aug 18, 2024
1 parent 7b458a9 commit 4732d81
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ self_update = { version = "0.41", default-features = false, features = [
] }
serde = "1.0.199"
serde_derive = "1.0.199"
serde_ignored = "0.1"
serde_json = { version = "1.0.116", features = [] }
sha2 = "0.10.8"
shell-escape = "0.1.5"
Expand Down
15 changes: 4 additions & 11 deletions src/config/config_file/mise_toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use crate::toolset::{ToolRequest, ToolRequestSet, ToolSource, ToolVersionOptions
use crate::{dirs, file};

#[derive(Default, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct MiseToml {
#[serde(default, deserialize_with = "deserialize_version")]
min_version: Option<Versioning>,
Expand Down Expand Up @@ -85,7 +84,10 @@ impl MiseToml {
pub fn from_file(path: &Path) -> eyre::Result<Self> {
trace!("parsing: {}", display_path(path));
let body = file::read_to_string(path)?;
let mut rf: MiseToml = toml::from_str(&body)?;
let des = toml::Deserializer::new(&body);
let mut rf: MiseToml = serde_ignored::deserialize(des, |p| {
warn!("unknown field in {}: {p}", display_path(path));
})?;
rf.context = BASE_CONTEXT.clone();
rf.context
.insert("config_root", path.parent().unwrap().to_str().unwrap());
Expand Down Expand Up @@ -1159,15 +1161,6 @@ mod tests {
assert_debug_snapshot!(cf);
}

#[test]
fn test_fail_with_unknown_key() {
reset();
let _ = toml::from_str::<MiseToml>(&formatdoc! {r#"
invalid_key = true
"#})
.unwrap_err();
}

#[test]
fn test_env_entries() {
reset();
Expand Down
1 change: 0 additions & 1 deletion src/config/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use crate::{config, dirs, env, file};
#[rustfmt::skip]
#[derive(Config, Default, Debug, Clone, Serialize)]
#[config(partial_attr(derive(Clone, Serialize, Default)))]
#[config(partial_attr(serde(deny_unknown_fields)))]
pub struct Settings {
/// push tools to the front of PATH instead of allowing modifications of PATH after activation to take precedence
#[config(env = "MISE_ACTIVATE_AGGRESSIVE", default = false)]
Expand Down

0 comments on commit 4732d81

Please sign in to comment.