Skip to content

Commit 866b6e5

Browse files
reivilibrebnjbvr
andauthored
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: [email protected] --------- Co-authored-by: Benjamin Bouvier <[email protected]>
1 parent 1e0e815 commit 866b6e5

File tree

2 files changed

+2
-19
lines changed

2 files changed

+2
-19
lines changed

crates/matrix-sdk/src/client/builder/mod.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -709,19 +709,6 @@ pub enum ClientBuildError {
709709
SqliteStore(#[from] matrix_sdk_sqlite::OpenStoreError),
710710
}
711711

712-
impl ClientBuildError {
713-
/// Assert that a valid homeserver URL was given to the builder and no other
714-
/// invalid options were specified, which means the only possible error
715-
/// case is [`Self::Http`].
716-
#[doc(hidden)]
717-
pub fn assert_valid_builder_args(self) -> HttpError {
718-
match self {
719-
ClientBuildError::Http(e) => e,
720-
_ => unreachable!("homeserver URL was asserted to be valid"),
721-
}
722-
}
723-
}
724-
725712
// The http mocking library is not supported for wasm32
726713
#[cfg(all(test, not(target_arch = "wasm32")))]
727714
pub(crate) mod tests {

crates/matrix-sdk/src/client/mod.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -386,12 +386,8 @@ impl Client {
386386
/// # Arguments
387387
///
388388
/// * `homeserver_url` - The homeserver that the client should connect to.
389-
pub async fn new(homeserver_url: Url) -> Result<Self, HttpError> {
390-
Self::builder()
391-
.homeserver_url(homeserver_url)
392-
.build()
393-
.await
394-
.map_err(ClientBuildError::assert_valid_builder_args)
389+
pub async fn new(homeserver_url: Url) -> Result<Self, ClientBuildError> {
390+
Self::builder().homeserver_url(homeserver_url).build().await
395391
}
396392

397393
/// Returns a subscriber that publishes an event every time the ignore user

0 commit comments

Comments
 (0)