chore: Box some error type variants

[Clippy's `result_large_err` lint](https://rust-lang.github.io/rust-clippy/master/index.html#result_large_err)
was complaining about the size of the error types, so boxing these
variants reduces the error sizes below the threshold of the lint.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
This commit is contained in:
Kévin Commaille
2026-07-19 11:19:19 +02:00
committed by Ivan Enderlin
parent f48c73176f
commit dd2aaa6159
6 changed files with 59 additions and 41 deletions

View File

@@ -71,7 +71,7 @@ pub enum ClientBuildError {
#[error(transparent)]
ServerUnreachable(HttpError),
#[error(transparent)]
WellKnownLookupFailed(RumaApiError),
WellKnownLookupFailed(Box<RumaApiError>),
#[error(transparent)]
WellKnownDeserializationError(DeserializationError),
#[error(transparent)]
@@ -94,12 +94,15 @@ impl From<MatrixClientBuildError> 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)
}

View File

@@ -76,7 +76,7 @@ async fn finish_login_grant<Q>(
message => {
return Err(QRCodeGrantLoginError::UnexpectedMessage {
expected: "m.login.protocol",
received: message,
received: Box::new(message),
});
}
};
@@ -140,7 +140,7 @@ async fn finish_login_grant<Q>(
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");

View File

@@ -97,7 +97,7 @@ async fn finish_login<Q>(
return Err(QRCodeLoginError::UnexpectedMessage {
expected: "m.login.protocol_accepted",
received: message,
received: Box::new(message),
});
}
}
@@ -176,7 +176,7 @@ async fn finish_login<Q>(
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),
});
}
};

View File

@@ -81,7 +81,7 @@ pub enum QRCodeLoginError {
/// The message we expected.
expected: &'static str,
/// The message we received instead.
received: QrAuthMessage,
received: Box<QrAuthMessage>,
},
/// 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<QrAuthMessage>,
},
/// The other device has signaled to us that the login has failed.

View File

@@ -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),
})?;

View File

@@ -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<RumaApiError>),
AutoDiscovery(Box<FromHttpResponseError<RumaApiError>>),
/// 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]