client builder: return a ClientBuildError when failing to build, instead of filtering out unexpected errors (#4016)

This old method was checking invariants that were
spooky-action-at-a-distance: these invariants have changed since then,
so this would panic instead of returning a proper error to the caller.

Signed-off-by: oliverw@element.io

---------

Co-authored-by: Benjamin Bouvier <benjamin@bouvier.cc>
This commit is contained in:
reivilibre
2024-09-30 11:43:25 +00:00
committed by GitHub
parent 1e0e815fab
commit 866b6e5f2d
2 changed files with 2 additions and 19 deletions

View File

@@ -709,19 +709,6 @@ pub enum ClientBuildError {
SqliteStore(#[from] matrix_sdk_sqlite::OpenStoreError),
}
impl ClientBuildError {
/// Assert that a valid homeserver URL was given to the builder and no other
/// invalid options were specified, which means the only possible error
/// case is [`Self::Http`].
#[doc(hidden)]
pub fn assert_valid_builder_args(self) -> HttpError {
match self {
ClientBuildError::Http(e) => e,
_ => unreachable!("homeserver URL was asserted to be valid"),
}
}
}
// The http mocking library is not supported for wasm32
#[cfg(all(test, not(target_arch = "wasm32")))]
pub(crate) mod tests {

View File

@@ -386,12 +386,8 @@ impl Client {
/// # Arguments
///
/// * `homeserver_url` - The homeserver that the client should connect to.
pub async fn new(homeserver_url: Url) -> Result<Self, HttpError> {
Self::builder()
.homeserver_url(homeserver_url)
.build()
.await
.map_err(ClientBuildError::assert_valid_builder_args)
pub async fn new(homeserver_url: Url) -> Result<Self, ClientBuildError> {
Self::builder().homeserver_url(homeserver_url).build().await
}
/// Returns a subscriber that publishes an event every time the ignore user