error on startup for unknown config file paths
Signed-off-by: June Strawberry <june@vern.cc>
This commit is contained in:
@@ -15,6 +15,7 @@ use either::{
|
|||||||
};
|
};
|
||||||
use figment::providers::{Env, Format, Toml};
|
use figment::providers::{Env, Format, Toml};
|
||||||
pub use figment::{Figment, value::Value as FigmentValue};
|
pub use figment::{Figment, value::Value as FigmentValue};
|
||||||
|
use itertools::Itertools;
|
||||||
use regex::RegexSet;
|
use regex::RegexSet;
|
||||||
use ruma::{
|
use ruma::{
|
||||||
OwnedMxcUri, OwnedRoomOrAliasId, OwnedServerName, OwnedUserId, RoomVersionId,
|
OwnedMxcUri, OwnedRoomOrAliasId, OwnedServerName, OwnedUserId, RoomVersionId,
|
||||||
@@ -27,8 +28,7 @@ use url::Url;
|
|||||||
use self::proxy::ProxyConfig;
|
use self::proxy::ProxyConfig;
|
||||||
pub use self::{check::check, manager::Manager};
|
pub use self::{check::check, manager::Manager};
|
||||||
use crate::{
|
use crate::{
|
||||||
Result, err,
|
Err, Result, err,
|
||||||
error::Error,
|
|
||||||
utils::{self, option::OptionExt, string::EMPTY, sys},
|
utils::{self, option::OptionExt, string::EMPTY, sys},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -2923,11 +2923,34 @@ impl Config {
|
|||||||
Env::var("TUWUNEL_CONFIG"),
|
Env::var("TUWUNEL_CONFIG"),
|
||||||
];
|
];
|
||||||
|
|
||||||
let config = envs
|
let toml_files = envs
|
||||||
.into_iter()
|
.iter()
|
||||||
.flatten()
|
.flatten()
|
||||||
|
.map(PathBuf::from)
|
||||||
|
.chain(paths.map(Path::to_path_buf))
|
||||||
|
.collect_vec();
|
||||||
|
|
||||||
|
let invalid_toml_files = toml_files
|
||||||
|
.iter()
|
||||||
|
.filter_map(|path| {
|
||||||
|
if !path.exists() {
|
||||||
|
Some(path.clone().into_os_string())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect_vec();
|
||||||
|
|
||||||
|
if !invalid_toml_files.is_empty() {
|
||||||
|
return Err!(
|
||||||
|
"The following config files do not exist or have broken symlinks: \
|
||||||
|
{invalid_toml_files:?}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let config = toml_files
|
||||||
|
.iter()
|
||||||
.map(Toml::file)
|
.map(Toml::file)
|
||||||
.chain(paths.map(Toml::file))
|
|
||||||
.fold(Figment::new(), |config, file| config.merge(file.nested()))
|
.fold(Figment::new(), |config, file| config.merge(file.nested()))
|
||||||
.merge(Env::prefixed("CONDUIT_").global().split("__"))
|
.merge(Env::prefixed("CONDUIT_").global().split("__"))
|
||||||
.merge(Env::prefixed("CONDUWUIT_").global().split("__"))
|
.merge(Env::prefixed("CONDUWUIT_").global().split("__"))
|
||||||
@@ -2978,7 +3001,7 @@ impl Config {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check(&self) -> Result<(), Error> { check(self) }
|
pub fn check(&self) -> Result { check(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn true_fn() -> bool { true }
|
fn true_fn() -> bool { true }
|
||||||
|
|||||||
Reference in New Issue
Block a user