1use std::{array::TryFromSliceError, time::SystemTimeError};
7
8use thiserror::Error;
9use tokio::{sync::oneshot::error::RecvError, task::JoinError};
10
11#[derive(Debug, Clone)]
13pub enum DisconnectReason {
14 PeerClosed,
15 ServerClosed,
16 ReadFrameError(String),
17 SendFrameError(String),
18 SendActivityError(String),
19 ClearActivityError(String),
20 ClientChannelClosed,
21 Unknown,
22}
23
24#[derive(Error, Debug)]
26pub enum PresenceError {
27 #[error("client error: {0}")]
28 ClientError(#[from] PresenceClientError),
29 #[error("runner error: {0}")]
30 RunnerError(#[from] PresenceRunnerError),
31}
32
33#[derive(Error, Debug)]
35pub enum PresenceClientError {
36 #[error("failed to send activity")]
37 ActivitySendError,
38 #[error("failed to receive from runner: {0}")]
39 OneShotRecvError(#[from] RecvError),
40}
41
42#[derive(Error, Debug)]
44pub enum PresenceRunnerError {
45 #[error("multiple `PresenceRunner::run` calls not allowed")]
46 MultipleRun,
47 #[error("failed to receive commands")]
48 ReceiverError,
49 #[error("background task exited before READY")]
50 ExitBeforeReady,
51 #[error("failed to await on task JoinHandle: {0}")]
52 JoinError(#[from] JoinError),
53}
54
55#[derive(Error, Debug)]
56pub(crate) enum DiscordSockError {
57 #[error("could not connect to pipe")]
58 PipeConnectionFailed,
59 #[error("pipe not found")]
60 PipeNotFound,
61 #[error("io error: {0}")]
62 IoError(#[from] std::io::Error),
63 #[error("failed to convert to u32 from_le_bytes: {0}")]
64 TryFromSliceError(#[from] TryFromSliceError),
65 #[error("failed to parse: {0}")]
66 ParseError(#[from] InnerParsingError),
67}
68
69#[derive(Error, Debug)]
70pub(crate) enum InnerParsingError {
71 #[error("failed to serialize to valid JSON: {0}")]
72 SerializeFailed(#[from] serde_json::Error),
73 #[error("failed to parse system time: {0}")]
74 SystemTimeError(#[from] SystemTimeError),
75}