From fd0e8b29a86444b772f71d5db767c201b04cad2b Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 29 Nov 2026 01:27:07 +0000 Subject: config: read names the option whose value doesn't fit Where the values set make none of what layer::read reads them into, its error names the option and where it was set, which serde doesn't: the first that alone makes none, as continuum found it for its settings; or, where what is read needs more than one option, the first without which the others make one. continuum reads its settings by it, and a party's client's options are named alike. --- src/config/mod.rs | 34 ++++------------------------------ 1 file changed, 4 insertions(+), 30 deletions(-) (limited to 'src/config/mod.rs') diff --git a/src/config/mod.rs b/src/config/mod.rs index 3e7c5d4..a32211e 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -29,9 +29,8 @@ use serde_json::Value as JsonValue; use tracing::{info, warn}; pub(crate) use ::config::arguments::{merged, with_options}; -#[cfg(feature = "federation")] pub(crate) use ::config::layer::read; -pub(crate) use ::config::layer::{Entry, Layer, Origin, Provenance}; +pub(crate) use ::config::layer::{Layer, Origin, Provenance}; pub(crate) use ::config::option::{Kind, OptionSpec, Schema, option}; /// What the node's configuration is read by: its options, those that can't be combined, @@ -49,7 +48,7 @@ pub(crate) const PARTY: Schema = Schema::of(PARTY_OPTIONS); /// As the crate's, by the node's options: what the tests call. #[cfg(test)] use ::config::{ - layer::{Overlay, unset_entry}, + layer::{Entry, Overlay, unset_entry}, option::from_text, }; @@ -1540,18 +1539,6 @@ const CONFLICTS: &[(&[&str], &[&str])] = &[( ], )]; -/// The first option whose value alone doesn't fit (serde doesn't name it). -fn culprit(merged: &Layer) -> Option<(&String, &Entry)> { - merged.iter().find(|(name, entry)| { - if entry.value.is_null() { - return false; - } - let mut alone = serde_json::Map::new(); - alone.insert((*name).clone(), entry.value.clone()); - serde_json::from_value::(JsonValue::Object(alone)).is_err() - }) -} - // --- command line -------------------------------------------------------------- const PRINT_CONFIG: &str = "print-config"; @@ -1825,22 +1812,9 @@ fn resolve(merged: Layer, files: Vec) -> Result { entry.origin ); } - // Unset options take their defaults. - let object: serde_json::Map = merged - .iter() - .filter(|(_, entry)| !entry.value.is_null()) - .map(|(name, entry)| (name.clone(), entry.value.clone())) - .collect(); + // Unset options take their defaults; an option whose value fits not is named. let mut settings: Settings = - serde_json::from_value(JsonValue::Object(object)).map_err(|error| { - match culprit(&merged) { - Some((name, entry)) => anyhow!( - "invalid configuration: option {name} (set in {}): {error}", - entry.origin - ), - None => anyhow!("invalid configuration: {error}"), - } - })?; + read(&merged).map_err(|error| anyhow!("invalid configuration: {error}"))?; settings.alias = settings.alias.map(|alias| alias.trim().to_owned()); settings.transports = settings.ordered_transports(); settings.check().context("invalid configuration")?; -- cgit v1.3.1