Skip to main content

soil_network/
error.rs

1// This file is part of Soil.
2
3// Copyright (C) Soil contributors.
4// Copyright (C) Parity Technologies (UK) Ltd.
5// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
6
7//! Substrate network possible errors.
8
9use crate::{config::TransportConfig, types::ProtocolName};
10
11use crate::types::{multiaddr::Multiaddr, PeerId};
12
13use std::fmt;
14
15/// Result type alias for the network.
16pub type Result<T> = std::result::Result<T, Error>;
17
18/// Error type for the network.
19#[derive(thiserror::Error)]
20pub enum Error {
21	/// Io error
22	#[error(transparent)]
23	Io(#[from] std::io::Error),
24
25	/// Client error
26	#[error(transparent)]
27	Client(#[from] Box<soil_client::blockchain::Error>),
28	/// The same bootnode (based on address) is registered with two different peer ids.
29	#[error(
30		"The same bootnode (`{address}`) is registered with two different peer ids: `{first_id}` and `{second_id}`"
31	)]
32	DuplicateBootnode {
33		/// The address of the bootnode.
34		address: Multiaddr,
35		/// The first peer id that was found for the bootnode.
36		first_id: PeerId,
37		/// The second peer id that was found for the bootnode.
38		second_id: PeerId,
39	},
40	/// Prometheus metrics error.
41	#[error(transparent)]
42	Prometheus(#[from] soil_prometheus::PrometheusError),
43	/// The network addresses are invalid because they don't match the transport.
44	#[error(
45		"The following addresses are invalid because they don't match the transport: {addresses:?}"
46	)]
47	AddressesForAnotherTransport {
48		/// Transport used.
49		transport: TransportConfig,
50		/// The invalid addresses.
51		addresses: Vec<Multiaddr>,
52	},
53	/// The same request-response protocol has been registered multiple times.
54	#[error("Request-response protocol registered multiple times: {protocol}")]
55	DuplicateRequestResponseProtocol {
56		/// Name of the protocol registered multiple times.
57		protocol: ProtocolName,
58	},
59	/// Peer does not exist.
60	#[error("Peer `{0}` does not exist.")]
61	PeerDoesntExist(PeerId),
62	/// Channel closed.
63	#[error("Channel closed")]
64	ChannelClosed,
65	/// Connection closed.
66	#[error("Connection closed")]
67	ConnectionClosed,
68	/// Litep2p error.
69	#[error("Litep2p error: `{0}`")]
70	Litep2p(litep2p::Error),
71}
72
73// Make `Debug` use the `Display` implementation.
74impl fmt::Debug for Error {
75	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
76		fmt::Display::fmt(self, f)
77	}
78}