From 76ea95634e87c8a2fb4332dc399e1025410a618f Mon Sep 17 00:00:00 2001 From: Charles Hall Date: Fri, 27 Sep 2024 17:47:17 -0700 Subject: [PATCH] make server name check errors much more specific This can help users by telling them how exactly the check failed, and telling them what the value in the database is, if any. --- src/error.rs | 12 ++++++++++-- src/service/globals.rs | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/error.rs b/src/error.rs index 69d6b38f..1ada3bbb 100644 --- a/src/error.rs +++ b/src/error.rs @@ -2,6 +2,7 @@ use std::{fmt, iter, path::PathBuf}; +use ruma::{OwnedServerName, OwnedUserId}; use thiserror::Error; use crate::config::ListenConfig; @@ -84,8 +85,15 @@ pub(crate) enum ServerNameChanged { #[error("failed to check if the admin bot exists")] AdminBotExists(#[source] crate::utils::error::Error), - #[error("`server_name` in the database and config file differ")] - Renamed, + #[error( + "`server_name` in the database ({0}) and config file ({1}) differ" + )] + Renamed(OwnedServerName, OwnedServerName), + + #[error( + "couldn't find {0} in the database, `server_name` must have changed" + )] + MissingAdminBot(OwnedUserId), #[error("failed to save the configured server_name")] SaveServerName(#[source] crate::utils::error::Error), diff --git a/src/service/globals.rs b/src/service/globals.rs index 0de48be0..00bbd7d9 100644 --- a/src/service/globals.rs +++ b/src/service/globals.rs @@ -332,7 +332,7 @@ impl Service { return Ok(()); } - return Err(Error::Renamed); + return Err(Error::Renamed(saved.clone(), config.to_owned())); } let non_zero_users = services() @@ -348,7 +348,7 @@ impl Service { // Fall back to checking against the admin bot user ID if non_zero_users && !admin_bot_exists { - return Err(Error::Renamed); + return Err(Error::MissingAdminBot(self.admin_bot_user_id.clone())); } // If the server_name wasn't saved and the admin bot user ID check