From 1589e80b28536af91aef8c8c1671d4c3c428e571 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Mon, 23 Nov 2026 15:38:42 +0000 Subject: [PATCH] Fix project config diagnostics after an unknown setting (#63377) ## Why When a project config contains an unknown key before an invalid setting, deserializing the effective config directly can mask the type error users need to fix. ## What changed Reuse the TOML validation deserializer when diagnosing effective config layers, with ignored-field path collection disabled. ## Testing Extend the project config diagnostic test with an unknown key and verify that the error still points to the invalid `tui.vim_mode_default` in the current file after filtering out `tui.status_line_provider`. GitOrigin-RevId: b124d0819ac34b2341f18fad7b6651ef0fe48379 --- codex-rs/config/src/diagnostics.rs | 12 +++++++++++- codex-rs/config/src/loader/tests.rs | 4 ++-- codex-rs/config/src/strict_config.rs | 14 +++++++++++++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/codex-rs/config/src/diagnostics.rs b/codex-rs/config/src/diagnostics.rs index 49bd6663f9..9b1f9d3c6a 100644 --- a/codex-rs/config/src/diagnostics.rs +++ b/codex-rs/config/src/diagnostics.rs @@ -8,6 +8,7 @@ use crate::ConfigLayerStack; use crate::config_toml::ConfigToml; use crate::format_config_layer_source; use crate::shell_environment_policy::ShellEnvironmentPolicyFilterConfigToml; +use crate::strict_config::validate_toml_value; use codex_utils_absolute_path::AbsolutePathBufGuard; use serde_path_to_error::Path as SerdePath; use serde_path_to_error::Segment as SerdeSegment; @@ -179,7 +180,16 @@ fn config_error_from_typed_toml_for_source( && let Ok(raw) = toml::from_str(contents) && let std::borrow::Cow::Owned(effective) = layer.effective_values(&raw) { - err = schema.deserialize_error(effective)?; + err = match schema { + DiagnosticSchema::Config => { + validate_toml_value::(effective, /*ignored_paths*/ None).err() + } + DiagnosticSchema::ShellEnvironmentFilters => serde_path_to_error::deserialize::< + _, + ShellEnvironmentPolicyFilterConfigToml, + >(effective) + .err(), + }?; } let path_hint = err.path().clone(); let toml_err: toml::de::Error = err.into_inner(); diff --git a/codex-rs/config/src/loader/tests.rs b/codex-rs/config/src/loader/tests.rs index 4ad5c6181c..b6ffd272b7 100644 --- a/codex-rs/config/src/loader/tests.rs +++ b/codex-rs/config/src/loader/tests.rs @@ -576,12 +576,12 @@ async fn project_diagnostic_uses_the_current_file_and_ignores_its_provider() -> ); std::fs::write( &path, - "[tui]\nstatus_line_provider = 42\nvim_mode_default = 43\n", + "ignored_setting = true\n[tui]\nstatus_line_provider = 42\nvim_mode_default = 43\n", )?; let error = first_layer_config_error_from_entries(&[layer]) .await .expect("invalid vim setting"); - assert_eq!((error.path, error.range.start.line), (path, 3)); + assert_eq!((error.path, error.range.start.line), (path, 4)); assert!(error.message.contains("43"), "{}", error.message); Ok(()) } diff --git a/codex-rs/config/src/strict_config.rs b/codex-rs/config/src/strict_config.rs index 0aec246329..e2ee765ec6 100644 --- a/codex-rs/config/src/strict_config.rs +++ b/codex-rs/config/src/strict_config.rs @@ -124,7 +124,19 @@ pub(crate) fn ignored_toml_value_fields( value: TomlValue, ) -> Result>, serde_path_to_error::Error> { let mut ignored_paths = Vec::new(); + validate_toml_value::(value, Some(&mut ignored_paths))?; + Ok(ignored_paths) +} + +/// Keep the same deserializer type whether or not the caller needs ignored field paths. +pub(crate) fn validate_toml_value( + value: TomlValue, + mut ignored_paths: Option<&mut Vec>>, +) -> Result<(), serde_path_to_error::Error> { let mut record_path = |path: serde_ignored::Path<'_>| { + let Some(ignored_paths) = &mut ignored_paths else { + return; + }; let segments = ignored_path_segments(&path); if !segments.is_empty() { ignored_paths.push(segments); @@ -132,7 +144,7 @@ pub(crate) fn ignored_toml_value_fields( }; let deserializer = serde_ignored::Deserializer::new(value, &mut record_path); serde_path_to_error::deserialize::<_, T>(deserializer)?; - Ok(ignored_paths) + Ok(()) } pub(crate) fn unknown_feature_toml_value_field(value: &TomlValue) -> Option {