use std::sync::Arc; use stanza::client::Stanza; use thiserror::Error; use tokio::{ sync::{mpsc::error::SendError, oneshot::error::RecvError}, time::error::Elapsed, }; #[derive(Debug, Error, Clone)] pub enum ConnectionError { #[error("connection failed: {0}")] ConnectionFailed(#[from] luz::Error), #[error("already connected")] AlreadyConnected, #[error("already disconnected")] AlreadyDisconnected, #[error("lost connection")] LostConnection, // TODO: Display for Content #[error("disconnected")] Disconnected, } #[derive(Debug, Error, Clone)] pub enum CommandError { #[error("actor: {0}")] Actor(ActorError), #[error("{0}")] Error(#[from] T), } #[derive(Debug, Error, Clone)] pub enum WriteError { #[error("xml: {0}")] XML(#[from] peanuts::Error), #[error("lost connection")] LostConnection, // TODO: should this be in writeerror or separate? #[error("actor: {0}")] Actor(#[from] ActorError), #[error("disconnected")] Disconnected, } // TODO: separate peanuts read and write error? // TODO: which crate #[derive(Debug, Error, Clone)] pub enum ReadError { #[error("xml: {0}")] XML(#[from] peanuts::Error), #[error("lost connection")] LostConnection, } #[derive(Debug, Error, Clone)] pub enum ActorError { #[error("receive timed out")] Timeout, #[error("could not send message to actor, channel closed")] Send, #[error("could not receive message from actor, channel closed")] Receive, } impl From for ActorError { fn from(_e: Elapsed) -> Self { Self::Timeout } } impl From> for ActorError { fn from(_e: SendError) -> Self { Self::Send } } impl From for ActorError { fn from(_e: RecvError) -> Self { Self::Receive } }