mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-28 20:17:57 +00:00
use thiserror instead of derive_more for error handling (#10696)
* use thiserror instead of derive_more for error handling Signed-off-by: koushiro <koushiro.cqx@gmail.com> * Update utils/prometheus/src/lib.rs * Update utils/prometheus/src/lib.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
@@ -27,18 +27,18 @@ use std::{borrow::Cow, fmt};
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
/// Error type for the network.
|
||||
#[derive(derive_more::Display, derive_more::From)]
|
||||
#[derive(thiserror::Error)]
|
||||
pub enum Error {
|
||||
/// Io error
|
||||
Io(std::io::Error),
|
||||
#[error(transparent)]
|
||||
Io(#[from] std::io::Error),
|
||||
|
||||
/// Client error
|
||||
Client(Box<sp_blockchain::Error>),
|
||||
#[error(transparent)]
|
||||
Client(#[from] Box<sp_blockchain::Error>),
|
||||
/// The same bootnode (based on address) is registered with two different peer ids.
|
||||
#[display(
|
||||
fmt = "The same bootnode (`{}`) is registered with two different peer ids: `{}` and `{}`",
|
||||
address,
|
||||
first_id,
|
||||
second_id
|
||||
#[error(
|
||||
"The same bootnode (`{address}`) is registered with two different peer ids: `{first_id}` and `{second_id}`"
|
||||
)]
|
||||
DuplicateBootnode {
|
||||
/// The address of the bootnode.
|
||||
@@ -49,11 +49,11 @@ pub enum Error {
|
||||
second_id: PeerId,
|
||||
},
|
||||
/// Prometheus metrics error.
|
||||
Prometheus(prometheus_endpoint::PrometheusError),
|
||||
#[error(transparent)]
|
||||
Prometheus(#[from] prometheus_endpoint::PrometheusError),
|
||||
/// The network addresses are invalid because they don't match the transport.
|
||||
#[display(
|
||||
fmt = "The following addresses are invalid because they don't match the transport: {:?}",
|
||||
addresses
|
||||
#[error(
|
||||
"The following addresses are invalid because they don't match the transport: {addresses:?}"
|
||||
)]
|
||||
AddressesForAnotherTransport {
|
||||
/// Transport used.
|
||||
@@ -62,7 +62,7 @@ pub enum Error {
|
||||
addresses: Vec<Multiaddr>,
|
||||
},
|
||||
/// The same request-response protocol has been registered multiple times.
|
||||
#[display(fmt = "Request-response protocol registered multiple times: {}", protocol)]
|
||||
#[error("Request-response protocol registered multiple times: {protocol}")]
|
||||
DuplicateRequestResponseProtocol {
|
||||
/// Name of the protocol registered multiple times.
|
||||
protocol: Cow<'static, str>,
|
||||
@@ -75,16 +75,3 @@ impl fmt::Debug for Error {
|
||||
fmt::Display::fmt(self, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for Error {
|
||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||
match self {
|
||||
Self::Io(ref err) => Some(err),
|
||||
Self::Client(ref err) => Some(err),
|
||||
Self::Prometheus(ref err) => Some(err),
|
||||
Self::DuplicateBootnode { .. } |
|
||||
Self::AddressesForAnotherTransport { .. } |
|
||||
Self::DuplicateRequestResponseProtocol { .. } => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user