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.
This commit is contained in:
Charles Hall 2024-09-27 17:47:17 -07:00
parent ea5605bbc3
commit 76ea95634e
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF
2 changed files with 12 additions and 4 deletions

View file

@ -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),

View file

@ -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