From 2211f324782cdc617b4b5ecd071178e372539fe4 Mon Sep 17 00:00:00 2001 From: cel 🌸 Date: Wed, 26 Mar 2025 14:29:40 +0000 Subject: refactor: rename crates and move client logic to separate crate `filament` --- lampada/src/error.rs | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 lampada/src/error.rs (limited to 'lampada/src/error.rs') diff --git a/lampada/src/error.rs b/lampada/src/error.rs new file mode 100644 index 0000000..cdfb4db --- /dev/null +++ b/lampada/src/error.rs @@ -0,0 +1,82 @@ +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 + } +} -- cgit