user-facing-error: Do not consume errors

Some errors do not implement Clone and we might want to keep them
around.
This commit is contained in:
Kévin Commaille 2023-11-18 17:08:31 +01:00 committed by Kévin Commaille
parent 1c4d275394
commit 05adb8408b
3 changed files with 11 additions and 11 deletions

View file

@ -64,7 +64,7 @@ pub enum SecretError {
}
impl UserFacingError for SecretError {
fn to_user_facing(self) -> String {
fn to_user_facing(&self) -> String {
match self {
SecretError::UnsupportedVersion { version, .. } => gettext_f(
// Translators: Do NOT translate the content between '{' and '}', this is a
@ -72,7 +72,7 @@ impl UserFacingError for SecretError {
"Found stored session with unsupported version {version_nb}",
&[("version_nb", &version.to_string())],
),
SecretError::Invalid(error) => error,
SecretError::Invalid(error) => error.clone(),
SecretError::Oo7(error) => error.to_user_facing(),
error => error.to_string(),
}
@ -80,7 +80,7 @@ impl UserFacingError for SecretError {
}
impl UserFacingError for oo7::Error {
fn to_user_facing(self) -> String {
fn to_user_facing(&self) -> String {
match self {
oo7::Error::Portal(error) => error.to_user_facing(),
oo7::Error::DBus(error) => error.to_user_facing(),
@ -89,7 +89,7 @@ impl UserFacingError for oo7::Error {
}
impl UserFacingError for oo7::portal::Error {
fn to_user_facing(self) -> String {
fn to_user_facing(&self) -> String {
match self {
oo7::portal::Error::FileHeaderMismatch(_) |
oo7::portal::Error::VersionMismatch(_) |
@ -129,7 +129,7 @@ impl UserFacingError for oo7::portal::Error {
}
impl UserFacingError for oo7::dbus::Error {
fn to_user_facing(self) -> String {
fn to_user_facing(&self) -> String {
match self {
oo7::dbus::Error::Deleted => gettext(
"The item was deleted.",

View file

@ -13,11 +13,11 @@ use matrix_sdk::{
use crate::ngettext_f;
pub trait UserFacingError {
fn to_user_facing(self) -> String;
fn to_user_facing(&self) -> String;
}
impl UserFacingError for HttpError {
fn to_user_facing(self) -> String {
fn to_user_facing(&self) -> String {
match self {
HttpError::Reqwest(error) => {
// TODO: Add more information based on the error
@ -54,7 +54,7 @@ impl UserFacingError for HttpError {
_ => {
// TODO: The server may not give us pretty enough error message. We should
// add our own error message.
message
message.clone()
}
}
}
@ -64,7 +64,7 @@ impl UserFacingError for HttpError {
}
impl UserFacingError for Error {
fn to_user_facing(self) -> String {
fn to_user_facing(&self) -> String {
match self {
Error::DecryptorError(_) => gettext("Could not decrypt the event"),
Error::Http(http_error) => http_error.to_user_facing(),
@ -74,7 +74,7 @@ impl UserFacingError for Error {
}
impl UserFacingError for ClientBuildError {
fn to_user_facing(self) -> String {
fn to_user_facing(&self) -> String {
match self {
ClientBuildError::Url(_) => gettext("This is not a valid URL"),
ClientBuildError::AutoDiscovery(_) => {

View file

@ -160,7 +160,7 @@ pub enum ClientSetupError {
}
impl UserFacingError for ClientSetupError {
fn to_user_facing(self) -> String {
fn to_user_facing(&self) -> String {
match self {
ClientSetupError::Client(err) => err.to_user_facing(),
ClientSetupError::Sdk(err) => err.to_user_facing(),