Distributed Erlang over iroh P2P + TLS, with a bot powers SDK
1//! Error types for erl_iroh.
2
3use thiserror::Error;
4
5/// Convenient result alias.
6pub type Result<T> = std::result::Result<T, Error>;
7
8/// Top-level error type.
9#[derive(Debug, Error)]
10pub enum Error {
11 /// I/O failure on a transport stream.
12 #[error("io error: {0}")]
13 Io(#[from] std::io::Error),
14
15 /// Erlang distribution handshake failed.
16 #[error("handshake error: {0}")]
17 Handshake(String),
18
19 /// Distribution message send failed.
20 #[error("send error: {0}")]
21 Send(String),
22
23 /// Distribution message receive failed.
24 #[error("recv error: {0}")]
25 Recv(String),
26
27 /// RPC call failed or returned an error term.
28 #[error("rpc error: {0}")]
29 Rpc(String),
30
31 /// Missing capability (bot power) for the requested operation.
32 #[error("power denied: need {needed}, have {have}")]
33 PowerDenied {
34 /// Required power name.
35 needed: &'static str,
36 /// Powers currently granted.
37 have: String,
38 },
39
40 /// Peer / node not found among connected sessions.
41 #[error("node not connected: {0}")]
42 NotConnected(String),
43
44 /// Invalid node name or endpoint id.
45 #[error("invalid name: {0}")]
46 InvalidName(String),
47
48 /// iroh endpoint / connection error.
49 #[error("iroh error: {0}")]
50 Iroh(String),
51
52 /// TLS configuration or handshake error.
53 #[error("tls error: {0}")]
54 Tls(String),
55
56 /// EPMD lookup failed.
57 #[error("epmd error: {0}")]
58 Epmd(String),
59
60 /// Session background task stopped.
61 #[error("session terminated")]
62 Terminated,
63
64 /// Operation timed out.
65 #[error("timeout")]
66 Timeout,
67
68 /// Catch-all for other failures.
69 #[error(transparent)]
70 Other(#[from] anyhow::Error),
71}
72
73impl Error {
74 pub(crate) fn handshake(e: impl ToString) -> Self {
75 Self::Handshake(e.to_string())
76 }
77
78 pub(crate) fn send(e: impl ToString) -> Self {
79 Self::Send(e.to_string())
80 }
81
82 pub(crate) fn recv(e: impl ToString) -> Self {
83 Self::Recv(e.to_string())
84 }
85
86 pub(crate) fn iroh(e: impl ToString) -> Self {
87 Self::Iroh(e.to_string())
88 }
89
90 pub(crate) fn tls(e: impl ToString) -> Self {
91 Self::Tls(e.to_string())
92 }
93
94 pub(crate) fn epmd(e: impl ToString) -> Self {
95 Self::Epmd(e.to_string())
96 }
97
98 pub(crate) fn rpc(e: impl ToString) -> Self {
99 Self::Rpc(e.to_string())
100 }
101}