1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use crate::envelope::Envelope;
use crate::message::Msg;
use crate::system::STRING_INTERNER;
use crate::{distributor::Distributor, message::BastionMessage};
use futures::channel::mpsc::TrySendError;
use std::fmt::Debug;
use std::time::Duration;
use thiserror::Error;
#[derive(Debug)]
pub enum ReceiveError {
Timeout(Duration),
Other,
}
#[derive(Error, Debug)]
pub enum SendError {
#[error("couldn't send message. Channel Disconnected.")]
Disconnected(Msg),
#[error("couldn't send message. Channel is Full.")]
Full(Msg),
#[error("couldn't send a message I should have not sent. {0}")]
Other(anyhow::Error),
#[error("No available Distributor matching {0}")]
NoDistributor(String),
#[error("Distributor has 0 Recipients")]
EmptyRecipient,
}
impl From<TrySendError<Envelope>> for SendError {
fn from(tse: TrySendError<Envelope>) -> Self {
let is_disconnected = tse.is_disconnected();
match tse.into_inner().msg {
BastionMessage::Message(msg) => {
if is_disconnected {
Self::Disconnected(msg)
} else {
Self::Full(msg)
}
}
other => Self::Other(anyhow::anyhow!("{:?}", other)),
}
}
}
impl From<Distributor> for SendError {
fn from(distributor: Distributor) -> Self {
Self::NoDistributor(STRING_INTERNER.resolve(distributor.interned()).to_string())
}
}