implement Clone for error types

This commit is contained in:
cel 🌸 2025-02-25 20:50:23 +00:00
parent d30131e0fc
commit 76b00cd644
3 changed files with 13 additions and 9 deletions

View File

@ -1,4 +1,5 @@
use std::str::Utf8Error; use std::str::Utf8Error;
use std::sync::Arc;
use jid::ParseError; use jid::ParseError;
use rsasl::mechname::MechanismNameError; use rsasl::mechname::MechanismNameError;
@ -6,9 +7,8 @@ use stanza::client::error::Error as ClientError;
use stanza::sasl::Failure; use stanza::sasl::Failure;
use stanza::stream::Error as StreamError; use stanza::stream::Error as StreamError;
use thiserror::Error; use thiserror::Error;
use tokio::task::JoinError;
#[derive(Error, Debug)] #[derive(Error, Debug, Clone)]
pub enum Error { pub enum Error {
#[error("connection")] #[error("connection")]
Connection, Connection,
@ -39,16 +39,20 @@ pub enum Error {
StreamError(#[from] StreamError), StreamError(#[from] StreamError),
#[error("error missing")] #[error("error missing")]
MissingError, MissingError,
#[error("task join error")]
JoinError(#[from] JoinError),
} }
#[derive(Error, Debug)] #[derive(Error, Debug, Clone)]
pub enum SASLError { pub enum SASLError {
#[error("sasl error: {0}")] #[error("sasl error: {0}")]
SASL(#[from] rsasl::prelude::SASLError), SASL(Arc<rsasl::prelude::SASLError>),
#[error("mechanism error: {0}")] #[error("mechanism error: {0}")]
MechanismName(#[from] MechanismNameError), MechanismName(#[from] MechanismNameError),
#[error("authentication failure: {0}")] #[error("authentication failure: {0}")]
Authentication(#[from] Failure), Authentication(#[from] Failure),
} }
impl From<rsasl::prelude::SASLError> for SASLError {
fn from(e: rsasl::prelude::SASLError) -> Self {
Self::SASL(Arc::new(e))
}
}

View File

@ -62,7 +62,7 @@ impl sqlx::Encode<'_, Sqlite> for JID {
} }
} }
#[derive(Debug)] #[derive(Debug, Clone)]
pub enum JIDError { pub enum JIDError {
NoResourcePart, NoResourcePart,
ParseError(ParseError), ParseError(ParseError),
@ -79,7 +79,7 @@ impl Display for JIDError {
impl Error for JIDError {} impl Error for JIDError {}
#[derive(Debug)] #[derive(Debug, Clone)]
pub enum ParseError { pub enum ParseError {
Empty, Empty,
Malformed(String), Malformed(String),

View File

@ -179,7 +179,7 @@ impl FromElement for Feature {
} }
} }
#[derive(Error, Debug)] #[derive(Error, Debug, Clone)]
pub struct Error { pub struct Error {
error: StreamError, error: StreamError,
text: Option<Text>, text: Option<Text>,