mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-17 15:51:23 +01:00
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:
parent
ea5605bbc3
commit
76ea95634e
2 changed files with 12 additions and 4 deletions
12
src/error.rs
12
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),
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue