aboutsummaryrefslogtreecommitdiffstats
path: root/lampada/src/error.rs
diff options
context:
space:
mode:
authorLibravatar cel 🌸 <cel@bunny.garden>2025-03-26 14:29:40 +0000
committerLibravatar cel 🌸 <cel@bunny.garden>2025-03-26 14:29:40 +0000
commit2211f324782cdc617b4b5ecd071178e372539fe4 (patch)
treea5ea5ce11d748424447dee23173d3cb8aec648ea /lampada/src/error.rs
parent2f8671978e18c1e1e7834056ae674f32fbde3868 (diff)
downloadluz-2211f324782cdc617b4b5ecd071178e372539fe4.tar.gz
luz-2211f324782cdc617b4b5ecd071178e372539fe4.tar.bz2
luz-2211f324782cdc617b4b5ecd071178e372539fe4.zip
refactor: rename crates and move client logic to separate crate `filament`
Diffstat (limited to 'lampada/src/error.rs')
-rw-r--r--lampada/src/error.rs82
1 files changed, 82 insertions, 0 deletions
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<T> {
+ #[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<Elapsed> for ActorError {
+ fn from(_e: Elapsed) -> Self {
+ Self::Timeout
+ }
+}
+
+impl<T> From<SendError<T>> for ActorError {
+ fn from(_e: SendError<T>) -> Self {
+ Self::Send
+ }
+}
+
+impl From<RecvError> for ActorError {
+ fn from(_e: RecvError) -> Self {
+ Self::Receive
+ }
+}