From e9caf228b3581e0ce458147bafa59deb590eb2f4 Mon Sep 17 00:00:00 2001 From: Charles Hall Date: Tue, 24 Sep 2024 17:18:22 -0700 Subject: [PATCH] move config check into config load function --- src/config.rs | 10 ++++++++-- src/database.rs | 4 ---- src/error.rs | 3 +++ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/config.rs b/src/config.rs index 394313e0..c1ebfeab 100644 --- a/src/config.rs +++ b/src/config.rs @@ -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) } diff --git a/src/database.rs b/src/database.rs index 2ab3bc6a..160a3093 100644 --- a/src/database.rs +++ b/src/database.rs @@ -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")?, diff --git a/src/error.rs b/src/error.rs index d2fcae24..180fc6a9 100644 --- a/src/error.rs +++ b/src/error.rs @@ -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