referrerpolicy=no-referrer-when-downgrade

sc_service/
error.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5
6// This program is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License
17// along with this program. If not, see <https://www.gnu.org/licenses/>.
18
19//! Errors that can occur during the service operation.
20
21use sc_keystore;
22use sp_blockchain;
23use sp_consensus;
24
25/// Service Result typedef.
26pub type Result<T> = std::result::Result<T, Error>;
27
28/// Service errors.
29#[derive(Debug, thiserror::Error)]
30#[allow(missing_docs)]
31#[non_exhaustive]
32pub enum Error {
33	#[error(transparent)]
34	Client(#[from] sp_blockchain::Error),
35
36	#[error(transparent)]
37	Io(#[from] std::io::Error),
38
39	#[error(transparent)]
40	Consensus(#[from] sp_consensus::Error),
41
42	#[error(transparent)]
43	Network(#[from] sc_network::error::Error),
44
45	#[error(transparent)]
46	Keystore(#[from] sc_keystore::Error),
47
48	#[error(transparent)]
49	Telemetry(#[from] sc_telemetry::Error),
50
51	#[error("Best chain selection strategy (SelectChain) is not provided.")]
52	SelectChainRequired,
53
54	#[error("Tasks executor hasn't been provided.")]
55	TaskExecutorRequired,
56
57	#[error("Prometheus metrics error: {0}")]
58	Prometheus(#[from] prometheus_endpoint::PrometheusError),
59
60	#[error("Application: {0}")]
61	Application(#[from] Box<dyn std::error::Error + Send + Sync + 'static>),
62
63	#[error("Other: {0}")]
64	Other(String),
65}
66
67impl<'a> From<&'a str> for Error {
68	fn from(s: &'a str) -> Self {
69		Error::Other(s.into())
70	}
71}
72
73impl From<String> for Error {
74	fn from(s: String) -> Self {
75		Error::Other(s)
76	}
77}