1use crate::{config::TransportConfig, types::ProtocolName};
10
11use crate::types::{multiaddr::Multiaddr, PeerId};
12
13use std::fmt;
14
15pub type Result<T> = std::result::Result<T, Error>;
17
18#[derive(thiserror::Error)]
20pub enum Error {
21 #[error(transparent)]
23 Io(#[from] std::io::Error),
24
25 #[error(transparent)]
27 Client(#[from] Box<soil_client::blockchain::Error>),
28 #[error(
30 "The same bootnode (`{address}`) is registered with two different peer ids: `{first_id}` and `{second_id}`"
31 )]
32 DuplicateBootnode {
33 address: Multiaddr,
35 first_id: PeerId,
37 second_id: PeerId,
39 },
40 #[error(transparent)]
42 Prometheus(#[from] soil_prometheus::PrometheusError),
43 #[error(
45 "The following addresses are invalid because they don't match the transport: {addresses:?}"
46 )]
47 AddressesForAnotherTransport {
48 transport: TransportConfig,
50 addresses: Vec<Multiaddr>,
52 },
53 #[error("Request-response protocol registered multiple times: {protocol}")]
55 DuplicateRequestResponseProtocol {
56 protocol: ProtocolName,
58 },
59 #[error("Peer `{0}` does not exist.")]
61 PeerDoesntExist(PeerId),
62 #[error("Channel closed")]
64 ChannelClosed,
65 #[error("Connection closed")]
67 ConnectionClosed,
68 #[error("Litep2p error: `{0}`")]
70 Litep2p(litep2p::Error),
71}
72
73impl fmt::Debug for Error {
75 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
76 fmt::Display::fmt(self, f)
77 }
78}