feat: check unsupported configuration entries with serde-ignored
This commit is contained in:
parent
84ec1e8973
commit
851cd58231
2 changed files with 17 additions and 1 deletions
|
|
@ -47,6 +47,7 @@ futures-util = { version = "0.3.31", default-features = false }
|
||||||
clap = { version = "4.5.20", features = ["std", "cargo", "wrap_help"] }
|
clap = { version = "4.5.20", features = ["std", "cargo", "wrap_help"] }
|
||||||
toml = { version = "0.8.19", default-features = false, features = ["parse"] }
|
toml = { version = "0.8.19", default-features = false, features = ["parse"] }
|
||||||
hot_reload = "0.1.6"
|
hot_reload = "0.1.6"
|
||||||
|
serde_ignored = "0.1.10"
|
||||||
|
|
||||||
# logging
|
# logging
|
||||||
tracing = { version = "0.1.40" }
|
tracing = { version = "0.1.40" }
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
constants::*,
|
constants::*,
|
||||||
error::{anyhow, ensure},
|
error::{anyhow, ensure},
|
||||||
|
log::warn,
|
||||||
};
|
};
|
||||||
use rpxy_lib::{reexports::Uri, AppConfig, ProxyConfig, ReverseProxyConfig, TlsConfig, UpstreamUri};
|
use rpxy_lib::{reexports::Uri, AppConfig, ProxyConfig, ReverseProxyConfig, TlsConfig, UpstreamUri};
|
||||||
use rustc_hash::FxHashMap as HashMap;
|
use rustc_hash::FxHashMap as HashMap;
|
||||||
|
|
@ -229,7 +230,21 @@ impl ConfigToml {
|
||||||
pub fn new(config_file: &str) -> std::result::Result<Self, anyhow::Error> {
|
pub fn new(config_file: &str) -> std::result::Result<Self, anyhow::Error> {
|
||||||
let config_str = fs::read_to_string(config_file)?;
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue