mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-13 18:45:44 -04:00
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:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user