diff --git a/rpxy-bin/Cargo.toml b/rpxy-bin/Cargo.toml index 85e2f44..a45fd59 100644 --- a/rpxy-bin/Cargo.toml +++ b/rpxy-bin/Cargo.toml @@ -47,6 +47,7 @@ futures-util = { version = "0.3.31", default-features = false } clap = { version = "4.5.20", features = ["std", "cargo", "wrap_help"] } toml = { version = "0.8.19", default-features = false, features = ["parse"] } hot_reload = "0.1.6" +serde_ignored = "0.1.10" # logging tracing = { version = "0.1.40" } diff --git a/rpxy-bin/src/config/toml.rs b/rpxy-bin/src/config/toml.rs index 9befc19..639f927 100644 --- a/rpxy-bin/src/config/toml.rs +++ b/rpxy-bin/src/config/toml.rs @@ -1,6 +1,7 @@ use crate::{ constants::*, error::{anyhow, ensure}, + log::warn, }; use rpxy_lib::{reexports::Uri, AppConfig, ProxyConfig, ReverseProxyConfig, TlsConfig, UpstreamUri}; use rustc_hash::FxHashMap as HashMap; @@ -229,7 +230,21 @@ impl ConfigToml { pub fn new(config_file: &str) -> std::result::Result { let config_str = fs::read_to_string(config_file)?; - toml::from_str(&config_str).map_err(|e| anyhow!(e)) + // Check unused fields during deserialization + let t = toml::de::Deserializer::new(&config_str); + let mut unused = rustc_hash::FxHashSet::default(); + + let res = serde_ignored::deserialize(t, |path| { + unused.insert(path.to_string()); + }) + .map_err(|e| anyhow!(e)); + + if !unused.is_empty() { + let str = unused.iter().fold(String::new(), |acc, x| acc + x + "\n"); + warn!("Configuration file contains unsupported fields. Check typos:\n{}", str); + } + + res } }