diff --git a/bindings/matrix-sdk-ffi/src/client_builder.rs b/bindings/matrix-sdk-ffi/src/client_builder.rs index 26d79340a..c67f679dc 100644 --- a/bindings/matrix-sdk-ffi/src/client_builder.rs +++ b/bindings/matrix-sdk-ffi/src/client_builder.rs @@ -71,7 +71,7 @@ pub enum ClientBuildError { #[error(transparent)] ServerUnreachable(HttpError), #[error(transparent)] - WellKnownLookupFailed(RumaApiError), + WellKnownLookupFailed(Box), #[error(transparent)] WellKnownDeserializationError(DeserializationError), #[error(transparent)] @@ -94,12 +94,15 @@ impl From for ClientBuildError { match e { MatrixClientBuildError::InvalidServerName => ClientBuildError::InvalidServerName, MatrixClientBuildError::Http(e) => ClientBuildError::ServerUnreachable(e), - MatrixClientBuildError::AutoDiscovery(FromHttpResponseError::Server(e)) => { - ClientBuildError::WellKnownLookupFailed(e) - } - MatrixClientBuildError::AutoDiscovery(FromHttpResponseError::Deserialization(e)) => { - ClientBuildError::WellKnownDeserializationError(e) - } + MatrixClientBuildError::AutoDiscovery(e) => match *e { + FromHttpResponseError::Server(e) => { + ClientBuildError::WellKnownLookupFailed(Box::new(e)) + } + FromHttpResponseError::Deserialization(e) => { + ClientBuildError::WellKnownDeserializationError(e) + } + _ => ClientBuildError::Sdk(MatrixClientBuildError::AutoDiscovery(e)), + }, MatrixClientBuildError::SlidingSyncVersion(e) => { ClientBuildError::SlidingSyncVersion(e) } diff --git a/crates/matrix-sdk/src/authentication/oauth/qrcode/grant.rs b/crates/matrix-sdk/src/authentication/oauth/qrcode/grant.rs index 20a73d832..229f812dd 100644 --- a/crates/matrix-sdk/src/authentication/oauth/qrcode/grant.rs +++ b/crates/matrix-sdk/src/authentication/oauth/qrcode/grant.rs @@ -76,7 +76,7 @@ async fn finish_login_grant( message => { return Err(QRCodeGrantLoginError::UnexpectedMessage { expected: "m.login.protocol", - received: message, + received: Box::new(message), }); } }; @@ -140,7 +140,7 @@ async fn finish_login_grant( message => { return Err(QRCodeGrantLoginError::UnexpectedMessage { expected: "m.login.success", - received: message, + received: Box::new(message), }); } } @@ -1287,13 +1287,17 @@ mod test { }); // Wait for all tasks to finish / fail. - assert_matches!( - grant.await, + assert_let!( Err(QRCodeGrantLoginError::UnexpectedMessage { expected: "m.login.protocol", - received: QrAuthMessage::LoginSuccess - }), - "Alice should abort the login with expected error" + received, + }) = grant.await, + "Alice should abort the login with expected error variant" + ); + assert_matches!( + *received, + QrAuthMessage::LoginSuccess, + "Alice should abort the login with expected error message" ); updates_task.await.expect("Alice should run through all progress states"); bob_task.await.expect("Bob's task should finish"); @@ -1398,13 +1402,17 @@ mod test { }); // Wait for all tasks to finish / fail. - assert_matches!( - grant.await, + assert_let!( Err(QRCodeGrantLoginError::UnexpectedMessage { expected: "m.login.protocol", - received: QrAuthMessage::LoginSuccess - }), - "Alice should abort the login with expected error" + received, + }) = grant.await, + "Alice should abort the login with expected error variant" + ); + assert_matches!( + *received, + QrAuthMessage::LoginSuccess, + "Alice should abort the login with expected error message" ); updates_task.await.expect("Alice should run through all progress states"); bob_task.await.expect("Bob's task should finish"); @@ -2711,13 +2719,17 @@ mod test { }); // Wait for all tasks to finish / fail. - assert_matches!( - grant.await, + assert_let!( Err(QRCodeGrantLoginError::UnexpectedMessage { expected: "m.login.success", - received: QrAuthMessage::LoginProtocolAccepted - }), - "Alice should abort the login with expected error" + received, + }) = grant.await, + "Alice should abort the login with expected error variant" + ); + assert_matches!( + *received, + QrAuthMessage::LoginProtocolAccepted, + "Alice should abort the login with expected error message" ); updates_task.await.expect("Alice should run through all progress states"); bob_task.await.expect("Bob's task should finish"); @@ -2840,13 +2852,17 @@ mod test { }); // Wait for all tasks to finish / fail. - assert_matches!( - grant.await, + assert_let!( Err(QRCodeGrantLoginError::UnexpectedMessage { expected: "m.login.success", - received: QrAuthMessage::LoginProtocolAccepted - }), - "Alice should abort the login with expected error" + received, + }) = grant.await, + "Alice should abort the login with expected error variant" + ); + assert_matches!( + *received, + QrAuthMessage::LoginProtocolAccepted, + "Alice should abort the login with expected error message" ); updates_task.await.expect("Alice should run through all progress states"); bob_task.await.expect("Bob's task should finish"); diff --git a/crates/matrix-sdk/src/authentication/oauth/qrcode/login.rs b/crates/matrix-sdk/src/authentication/oauth/qrcode/login.rs index a642aeddb..24d3a3885 100644 --- a/crates/matrix-sdk/src/authentication/oauth/qrcode/login.rs +++ b/crates/matrix-sdk/src/authentication/oauth/qrcode/login.rs @@ -97,7 +97,7 @@ async fn finish_login( return Err(QRCodeLoginError::UnexpectedMessage { expected: "m.login.protocol_accepted", - received: message, + received: Box::new(message), }); } } @@ -176,7 +176,7 @@ async fn finish_login( return Err(QRCodeLoginError::UnexpectedMessage { expected: "m.login.secrets", - received: message, + received: Box::new(message), }); } }; @@ -410,7 +410,7 @@ impl<'a> IntoFuture for LoginWithGeneratedQrCode<'a> { return Err(QRCodeLoginError::UnexpectedMessage { expected: "m.login.protocols", - received: message, + received: Box::new(message), }); } }; diff --git a/crates/matrix-sdk/src/authentication/oauth/qrcode/mod.rs b/crates/matrix-sdk/src/authentication/oauth/qrcode/mod.rs index c1af524b1..c9b4ddcd2 100644 --- a/crates/matrix-sdk/src/authentication/oauth/qrcode/mod.rs +++ b/crates/matrix-sdk/src/authentication/oauth/qrcode/mod.rs @@ -81,7 +81,7 @@ pub enum QRCodeLoginError { /// The message we expected. expected: &'static str, /// The message we received instead. - received: QrAuthMessage, + received: Box, }, /// An error happened while exchanging messages with the other device. @@ -178,7 +178,7 @@ pub enum QRCodeGrantLoginError { /// The message we expected. expected: &'static str, /// The message we received instead. - received: QrAuthMessage, + received: Box, }, /// The other device has signaled to us that the login has failed. diff --git a/crates/matrix-sdk/src/client/builder/homeserver_config.rs b/crates/matrix-sdk/src/client/builder/homeserver_config.rs index 2c1c3b8e2..d6167c664 100644 --- a/crates/matrix-sdk/src/client/builder/homeserver_config.rs +++ b/crates/matrix-sdk/src/client/builder/homeserver_config.rs @@ -187,7 +187,7 @@ async fn discover_homeserver( ) .await .map_err(|e| match e { - HttpError::Api(err) => ClientBuildError::AutoDiscovery(*err), + HttpError::Api(err) => ClientBuildError::AutoDiscovery(err), err => ClientBuildError::Http(err), })?; diff --git a/crates/matrix-sdk/src/client/builder/mod.rs b/crates/matrix-sdk/src/client/builder/mod.rs index 16e4c23a0..cf2ba9980 100644 --- a/crates/matrix-sdk/src/client/builder/mod.rs +++ b/crates/matrix-sdk/src/client/builder/mod.rs @@ -856,7 +856,7 @@ pub enum ClientBuildError { /// Error looking up the .well-known endpoint on auto-discovery #[error("Error looking up the .well-known endpoint on auto-discovery")] - AutoDiscovery(FromHttpResponseError), + AutoDiscovery(Box>), /// Error when building the sliding sync version. #[error(transparent)] @@ -961,7 +961,8 @@ pub(crate) mod tests { let error = builder.build().await.unwrap_err(); // Then the operation should fail with a server discovery error. - assert_matches!(error, ClientBuildError::AutoDiscovery(FromHttpResponseError::Server(_))); + assert_let!(ClientBuildError::AutoDiscovery(e) = error); + assert_matches!(*e, FromHttpResponseError::Server(_)); } #[async_test] @@ -998,10 +999,8 @@ pub(crate) mod tests { let error = builder.build().await.unwrap_err(); // Then the operation should fail due to the well-known file's contents. - assert_matches!( - error, - ClientBuildError::AutoDiscovery(FromHttpResponseError::Deserialization(_)) - ); + assert_let!(ClientBuildError::AutoDiscovery(e) = error); + assert_matches!(*e, FromHttpResponseError::Deserialization(_)); } #[async_test]