warn if a catchall config option (unknown config option) exists

a longer way of saying: warn if a config key is unknown

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-02-08 19:19:28 -05:00 committed by June
parent d4d8c6eb21
commit 6996d63a02
2 changed files with 13 additions and 1 deletions

View file

@ -11,7 +11,7 @@ use itertools::Itertools;
use regex::RegexSet;
use ruma::{OwnedServerName, RoomVersionId};
use serde::{de::IgnoredAny, Deserialize};
use tracing::{error, warn};
use tracing::{debug, error, warn};
mod proxy;
@ -157,6 +157,7 @@ const DEPRECATED_KEYS: &[&str] = &["cache_capacity"];
impl Config {
/// Iterates over all the keys in the config file and warns if there is a deprecated key specified
pub fn warn_deprecated(&self) {
debug!("Checking for deprecated config keys");
let mut was_deprecated = false;
for key in self
.catchall
@ -172,6 +173,14 @@ impl Config {
}
}
/// iterates over all the catchall keys (unknown config options) and warns if there are any.
pub fn warn_unknown_key(&self) {
debug!("Checking for unknown config keys");
for key in self.catchall.keys() {
warn!("Config parameter \"{}\" is unknown to conduwuit.", key);
}
}
/// Checks the presence of the `address` and `unix_socket_path` keys in the raw_config, exiting the process if both keys were detected.
pub fn is_dual_listening(&self, raw_config: Figment) -> bool {
let check_address = raw_config.find_value("address");

View file

@ -136,6 +136,9 @@ async fn main() {
maximize_fd_limit().expect("Unable to increase maximum soft and hard file descriptor limit");
config.warn_deprecated();
config.warn_unknown_key();
// don't start if we're listening on both UNIX sockets and TCP at same time
if config.is_dual_listening(raw_config) {
return;
};