federation_net/error.rs
1//! Error types for the federation-net library.
2
3use iroh::EndpointId;
4
5/// Convenient result alias used across the library.
6pub type Result<T, E = NetworkError> = std::result::Result<T, E>;
7
8/// All errors that can be returned by the public API of this library.
9#[derive(Debug, thiserror::Error)]
10#[non_exhaustive]
11pub enum NetworkError {
12 /// The provided [`crate::NetworkConfig`] is invalid.
13 #[error("invalid configuration: {0}")]
14 InvalidConfig(String),
15
16 /// Loading or persisting the peer identity failed.
17 #[error("identity error: {0}")]
18 Identity(String),
19
20 /// A peer ticket could not be parsed or validated.
21 #[error("invalid ticket: {0}")]
22 InvalidTicket(String),
23
24 /// The remote peer belongs to a different network.
25 #[error("network id mismatch")]
26 NetworkMismatch,
27
28 /// The remote peer uses an incompatible message schema.
29 #[error("schema id mismatch")]
30 SchemaMismatch,
31
32 /// The remote peer speaks an unsupported protocol version.
33 #[error("unsupported protocol version")]
34 UnsupportedProtocolVersion,
35
36 /// The remote peer rejected the handshake as malformed.
37 #[error("handshake rejected as invalid by remote peer")]
38 HandshakeRejected,
39
40 /// No active connection to the given peer exists.
41 #[error("peer is not connected: {0}")]
42 PeerNotConnected(EndpointId),
43
44 /// A message exceeds the configured maximum size.
45 #[error("message exceeds maximum size")]
46 MessageTooLarge,
47
48 /// The operation did not complete within the configured timeout.
49 #[error("request timed out")]
50 Timeout,
51
52 /// Encoding or decoding a wire payload failed.
53 #[error("serialization error: {0}")]
54 Serialization(String),
55
56 /// The underlying Iroh transport reported an error.
57 #[error("transport error: {0}")]
58 Transport(String),
59
60 /// The remote peer rejected a message.
61 #[error("message rejected by peer: {0}")]
62 MessageRejected(String),
63
64 /// The given ALPN was not declared as a stream protocol in the
65 /// configuration.
66 #[error("unknown stream protocol: {0}")]
67 UnknownStreamProtocol(String),
68
69 /// The incoming-stream acceptor for this protocol was already taken.
70 #[error("stream acceptor already taken: {0}")]
71 StreamAcceptorTaken(String),
72
73 /// The engine is shutting down and no longer accepts operations.
74 #[error("engine is shutting down")]
75 ShuttingDown,
76}