1use concurrent_queue::PushError;
4use std::any::Any;
5use thiserror::Error;
6
7#[derive(Debug, Clone, PartialEq, Eq, Hash, Error)]
11#[error("Process has been halted")]
12pub struct HaltedError;
13
14#[derive(Debug, Clone, PartialEq, Eq, Hash, Error)]
16pub enum RecvError {
17 #[error("Couldn't receive because the process has been halted")]
19 Halted,
20 #[error("Couldn't receive becuase the channel is closed and empty")]
23 ClosedAndEmpty,
24}
25
26#[derive(Debug, Clone, PartialEq, Eq, Hash, Error)]
28pub enum TryRecvError {
29 #[error("Couldn't receive because the process has been halted")]
31 Halted,
32 #[error("Couldn't receive because the channel is empty")]
34 Empty,
35 #[error("Couldn't receive becuase the channel is closed and empty")]
38 ClosedAndEmpty,
39}
40
41#[derive(Debug, Clone, PartialEq, Eq, Hash, Error)]
43pub enum TrySendError<M> {
44 #[error("Couldn't send message because Channel is closed")]
46 Closed(M),
47 #[error("Couldn't send message because Channel is full")]
49 Full(M),
50}
51
52impl<M> From<PushError<M>> for TrySendError<M> {
53 fn from(e: PushError<M>) -> Self {
54 match e {
55 PushError::Full(msg) => Self::Full(msg),
56 PushError::Closed(msg) => Self::Closed(msg),
57 }
58 }
59}
60
61#[derive(Debug, Clone, PartialEq, Eq, Hash, Error)]
65pub struct SendError<M>(pub M);
66
67#[derive(Clone, PartialEq, Eq, Hash, Error)]
69pub enum TrySpawnError<T> {
70 #[error("Couldn't spawn process because the actor has exited")]
72 Exited(T),
73 #[error("Couldn't spawn process because the given inbox-type is incorrect")]
75 IncorrectType(T),
76}
77
78impl<T> std::fmt::Debug for TrySpawnError<T> {
79 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
80 match self {
81 Self::Exited(_) => f.debug_tuple("Exited").finish(),
82 Self::IncorrectType(_) => f.debug_tuple("IncorrectType").finish(),
83 }
84 }
85}
86
87#[derive(Clone, PartialEq, Eq, Hash, Error)]
91#[error("Couldn't spawn process because the channel has exited")]
92pub struct SpawnError<T>(pub T);
93
94impl<T> std::fmt::Debug for SpawnError<T> {
95 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
96 f.debug_tuple("SpawnError").finish()
97 }
98}
99
100#[derive(Debug, Error)]
102pub enum ExitError {
103 #[error("Process has exited because of a panic")]
105 Panic(Box<dyn Any + Send>),
106 #[error("Process has exited because it was aborted")]
108 Abort,
109}
110
111impl ExitError {
112 pub fn is_panic(&self) -> bool {
114 match self {
115 ExitError::Panic(_) => true,
116 ExitError::Abort => false,
117 }
118 }
119
120 pub fn is_abort(&self) -> bool {
122 match self {
123 ExitError::Panic(_) => false,
124 ExitError::Abort => true,
125 }
126 }
127}
128
129impl From<tokio::task::JoinError> for ExitError {
130 fn from(e: tokio::task::JoinError) -> Self {
131 match e.try_into_panic() {
132 Ok(panic) => ExitError::Panic(panic),
133 Err(_) => ExitError::Abort,
134 }
135 }
136}