1use std::{array::TryFromSliceError, time::SystemTimeError};
7
8use thiserror::Error;
9use tokio::{sync::oneshot::error::RecvError, task::JoinError};
10
11#[derive(Error, Debug)]
13pub enum ActivitySpecBuildError {
14 #[error("image assets are provided without the image itself")]
15 ImageAssetsTooEarly,
16 #[error("status display points to {0} but {0} is not set")]
17 StatusDisplayElementMissing(&'static str),
18 #[error("{0}_url provided but {0} itself is missing")]
19 ElementURLProvidedEarly(&'static str),
20}
21
22#[derive(Debug, Clone)]
24pub enum DisconnectReason {
25 PeerClosed,
26 ServerClosed,
27 OldRelicComputer(String),
28 ReadFrameError(String),
29 SendFrameError(String),
30 SendActivityError(String),
31 ClearActivityError(String),
32 ClientChannelClosed,
33 Unknown,
34}
35
36#[derive(Error, Debug)]
38pub enum PresenceError {
39 #[error("client error: {0}")]
40 ClientError(#[from] PresenceClientError),
41 #[error("runner error: {0}")]
42 RunnerError(#[from] PresenceRunnerError),
43 #[error("activity spec build error: {0}")]
44 BuildError(#[from] ActivitySpecBuildError),
45}
46
47#[derive(Error, Debug)]
49pub enum PresenceClientError {
50 #[error("failed to send activity")]
51 ActivitySendError,
52 #[error("failed to receive from runner: {0}")]
53 OneShotRecvError(#[from] RecvError),
54}
55
56#[derive(Error, Debug)]
58pub enum PresenceRunnerError {
59 #[error("multiple `PresenceRunner::run` calls not allowed")]
60 MultipleRun,
61 #[error("failed to receive commands")]
62 ReceiverError,
63 #[error("background task exited before READY")]
64 ExitBeforeReady,
65 #[error("failed to await on task JoinHandle: {0}")]
66 JoinError(#[from] JoinError),
67}
68
69#[derive(Error, Debug)]
70pub(crate) enum DiscordSockError {
71 #[error("could not connect to pipe")]
72 PipeConnectionFailed,
73 #[error("pipe not found")]
74 PipeNotFound,
75 #[error("io error: {0}")]
76 IoError(#[from] std::io::Error),
77 #[error("failed to convert to u32 from_le_bytes: {0}")]
78 TryFromSliceError(#[from] TryFromSliceError),
79 #[error("payload size {size} exceeds maximum allowed size {max}")]
80 PayloadTooLarge { size: usize, max: usize },
81 #[error("failed to parse: {0}")]
82 ParseError(#[from] InnerParsingError),
83 #[error("invalid opcode")]
84 OpcodeError,
85}
86
87#[derive(Error, Debug)]
88pub(crate) enum InnerParsingError {
89 #[error("failed to serialize to valid JSON: {0}")]
90 SerializeFailed(#[from] serde_json::Error),
91 #[error("failed to parse system time: {0}")]
92 SystemTimeError(#[from] SystemTimeError),
93}