Skip to main content

soil_service/
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//! Errors that can occur during the service operation.
8
9use soil_client::blockchain;
10use soil_client::consensus;
11use soil_client::keystore;
12
13/// Service Result typedef.
14pub type Result<T> = std::result::Result<T, Error>;
15
16/// Service errors.
17#[derive(Debug, thiserror::Error)]
18#[allow(missing_docs)]
19#[non_exhaustive]
20pub enum Error {
21	#[error(transparent)]
22	Client(#[from] soil_client::blockchain::Error),
23
24	#[error(transparent)]
25	Io(#[from] std::io::Error),
26
27	#[error(transparent)]
28	Consensus(#[from] soil_client::consensus::Error),
29
30	#[error(transparent)]
31	Network(#[from] soil_network::error::Error),
32
33	#[error(transparent)]
34	Keystore(#[from] soil_client::keystore::Error),
35
36	#[error(transparent)]
37	Telemetry(#[from] soil_telemetry::Error),
38
39	#[error("Best chain selection strategy (SelectChain) is not provided.")]
40	SelectChainRequired,
41
42	#[error("Tasks executor hasn't been provided.")]
43	TaskExecutorRequired,
44
45	#[error("Prometheus metrics error: {0}")]
46	Prometheus(#[from] soil_prometheus::PrometheusError),
47
48	#[error("Application: {0}")]
49	Application(#[from] Box<dyn std::error::Error + Send + Sync + 'static>),
50
51	#[error("Other: {0}")]
52	Other(String),
53}
54
55impl<'a> From<&'a str> for Error {
56	fn from(s: &'a str) -> Self {
57		Error::Other(s.into())
58	}
59}
60
61impl From<String> for Error {
62	fn from(s: String) -> Self {
63		Error::Other(s)
64	}
65}