use std::{array::TryFromSliceError, time::SystemTimeError};
use thiserror::Error;
use tokio::{sync::oneshot::error::RecvError, task::JoinError};
#[derive(Debug, Clone)]
pub enum DisconnectReason {
PeerClosed,
ServerClosed,
ReadFrameError(String),
SendFrameError(String),
SendActivityError(String),
ClearActivityError(String),
ClientChannelClosed,
Unknown,
}
#[derive(Error, Debug)]
pub enum PresenceError {
#[error("client error: {0}")]
ClientError(#[from] PresenceClientError),
#[error("runner error: {0}")]
RunnerError(#[from] PresenceRunnerError),
}
#[derive(Error, Debug)]
pub enum PresenceClientError {
#[error("failed to send activity")]
ActivitySendError,
#[error("failed to receive from runner: {0}")]
OneShotRecvError(#[from] RecvError),
}
#[derive(Error, Debug)]
pub enum PresenceRunnerError {
#[error("multiple `PresenceRunner::run` calls not allowed")]
MultipleRun,
#[error("failed to receive commands")]
ReceiverError,
#[error("background task exited before READY")]
ExitBeforeReady,
#[error("failed to await on task JoinHandle: {0}")]
JoinError(#[from] JoinError),
}
#[derive(Error, Debug)]
pub(crate) enum DiscordSockError {
#[error("could not connect to pipe")]
PipeConnectionFailed,
#[error("pipe not found")]
PipeNotFound,
#[error("io error: {0}")]
IoError(#[from] std::io::Error),
#[error("failed to convert to u32 from_le_bytes: {0}")]
TryFromSliceError(#[from] TryFromSliceError),
#[error("failed to parse: {0}")]
ParseError(#[from] InnerParsingError),
}
#[derive(Error, Debug)]
pub(crate) enum InnerParsingError {
#[error("failed to serialize to valid JSON: {0}")]
SerializeFailed(#[from] serde_json::Error),
#[error("failed to parse system time: {0}")]
SystemTimeError(#[from] SystemTimeError),
}