mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-16 15:21:24 +01:00
move config check into config load function
This commit is contained in:
parent
75ef57e0ce
commit
e9caf228b3
3 changed files with 11 additions and 6 deletions
|
|
@ -438,10 +438,16 @@ where
|
|||
|
||||
let path = path.as_ref();
|
||||
|
||||
toml::from_str(
|
||||
let config: Config = toml::from_str(
|
||||
&tokio::fs::read_to_string(path)
|
||||
.await
|
||||
.map_err(|e| Error::Read(e, path.to_owned()))?,
|
||||
)
|
||||
.map_err(|e| Error::Parse(e, path.to_owned()))
|
||||
.map_err(|e| Error::Parse(e, path.to_owned()))?;
|
||||
|
||||
if config.registration_token.as_deref() == Some("") {
|
||||
return Err(Error::RegistrationTokenEmpty);
|
||||
}
|
||||
|
||||
Ok(config)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -353,10 +353,6 @@ impl KeyValueDatabase {
|
|||
}
|
||||
};
|
||||
|
||||
if config.registration_token == Some(String::new()) {
|
||||
return Err(Error::bad_config("Registration token is empty"));
|
||||
}
|
||||
|
||||
let db_raw = Box::new(Self {
|
||||
db: builder.clone(),
|
||||
userid_password: builder.open_tree("userid_password")?,
|
||||
|
|
|
|||
|
|
@ -95,6 +95,9 @@ pub(crate) enum Config {
|
|||
|
||||
#[error("failed to parse configuration file {1:?}")]
|
||||
Parse(#[source] toml::de::Error, PathBuf),
|
||||
|
||||
#[error("registration token must not be empty")]
|
||||
RegistrationTokenEmpty,
|
||||
}
|
||||
|
||||
/// Errors that can occur while searching for a config file
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue