mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-24 05:25:48 +00:00
Unify error enums in substrate and ethereum clients with thiserror (#1094)
* Unify error enums in substrate and ethereum clients with `thiserror` Related to https://github.com/paritytech/parity-bridges-common/issues/857 * Add license pre-amble * rustfmt * Fix spelling
This commit is contained in:
committed by
Bastian Köcher
parent
7b4f1c2236
commit
5842968273
@@ -15,6 +15,7 @@
|
||||
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::{
|
||||
error::Error,
|
||||
metrics::{Metrics, MetricsAddress, MetricsParams, PrometheusError, StandaloneMetrics},
|
||||
FailedClient, MaybeConnectionError,
|
||||
};
|
||||
@@ -116,7 +117,7 @@ impl<SC, TC, LM> Loop<SC, TC, LM> {
|
||||
/// This function represents an outer loop, which in turn calls provided `run_loop` function to
|
||||
/// do actual job. When `run_loop` returns, this outer loop reconnects to failed client (source,
|
||||
/// target or both) and calls `run_loop` again.
|
||||
pub async fn run<R, F>(mut self, loop_name: String, run_loop: R) -> anyhow::Result<()>
|
||||
pub async fn run<R, F>(mut self, loop_name: String, run_loop: R) -> Result<(), Error>
|
||||
where
|
||||
R: 'static + Send + Fn(SC, TC, Option<LM>) -> F,
|
||||
F: 'static + Send + Future<Output = Result<(), FailedClient>>,
|
||||
@@ -162,7 +163,7 @@ impl<SC, TC, LM> LoopMetrics<SC, TC, LM> {
|
||||
pub fn loop_metric<NewLM: Metrics>(
|
||||
self,
|
||||
create_metric: impl FnOnce(&Registry, Option<&str>) -> Result<NewLM, PrometheusError>,
|
||||
) -> anyhow::Result<LoopMetrics<SC, TC, NewLM>> {
|
||||
) -> Result<LoopMetrics<SC, TC, NewLM>, Error> {
|
||||
let loop_metric = create_metric(&self.registry, self.metrics_prefix.as_deref())?;
|
||||
|
||||
Ok(LoopMetrics {
|
||||
@@ -178,13 +179,13 @@ impl<SC, TC, LM> LoopMetrics<SC, TC, LM> {
|
||||
pub fn standalone_metric<M: StandaloneMetrics>(
|
||||
self,
|
||||
create_metric: impl FnOnce(&Registry, Option<&str>) -> Result<M, PrometheusError>,
|
||||
) -> anyhow::Result<Self> {
|
||||
) -> Result<Self, Error> {
|
||||
// since standalone metrics are updating themselves, we may just ignore the fact that the
|
||||
// same standalone metric is exposed by several loops && only spawn single metric
|
||||
match create_metric(&self.registry, self.metrics_prefix.as_deref()) {
|
||||
Ok(standalone_metrics) => standalone_metrics.spawn(),
|
||||
Err(PrometheusError::AlreadyReg) => (),
|
||||
Err(e) => anyhow::bail!(e),
|
||||
Err(e) => return Err(e.into()),
|
||||
}
|
||||
|
||||
Ok(self)
|
||||
@@ -202,16 +203,13 @@ impl<SC, TC, LM> LoopMetrics<SC, TC, LM> {
|
||||
/// Expose metrics using address passed at creation.
|
||||
///
|
||||
/// If passed `address` is `None`, metrics are not exposed.
|
||||
pub async fn expose(self) -> anyhow::Result<Loop<SC, TC, LM>> {
|
||||
pub async fn expose(self) -> Result<Loop<SC, TC, LM>, Error> {
|
||||
if let Some(address) = self.address {
|
||||
let socket_addr = SocketAddr::new(
|
||||
address.host.parse().map_err(|err| {
|
||||
anyhow::format_err!(
|
||||
"Invalid host {} is used to expose Prometheus metrics: {}",
|
||||
address.host,
|
||||
err,
|
||||
)
|
||||
})?,
|
||||
address
|
||||
.host
|
||||
.parse()
|
||||
.map_err(|err| Error::ExposingMetricsInvalidHost(address.host.clone(), err))?,
|
||||
address.port,
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user