referrerpolicy=no-referrer-when-downgrade

polkadot_node_core_provisioner/
error.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Polkadot.
3
4// Polkadot is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Polkadot is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Polkadot.  If not, see <http://www.gnu.org/licenses/>.
16
17///! Error types for provisioner module
18use fatality::Nested;
19use futures::channel::{mpsc, oneshot};
20use polkadot_node_subsystem::errors::{ChainApiError, RuntimeApiError, SubsystemError};
21use polkadot_node_subsystem_util as util;
22use polkadot_primitives::Hash;
23
24pub type FatalResult<T> = std::result::Result<T, FatalError>;
25pub type Result<T> = std::result::Result<T, Error>;
26
27/// Errors in the provisioner.
28#[allow(missing_docs)]
29#[fatality::fatality(splitable)]
30pub enum Error {
31	#[fatal(forward)]
32	#[error("Error while accessing runtime information")]
33	Runtime(#[from] util::runtime::Error),
34
35	#[error(transparent)]
36	Util(#[from] util::Error),
37
38	#[error("failed to get availability cores")]
39	CanceledAvailabilityCores(#[source] oneshot::Canceled),
40
41	#[error("failed to get persisted validation data")]
42	CanceledPersistedValidationData(#[source] oneshot::Canceled),
43
44	#[error("failed to get block number")]
45	CanceledBlockNumber(#[source] oneshot::Canceled),
46
47	#[error("failed to get session index")]
48	CanceledSessionIndex(#[source] oneshot::Canceled),
49
50	#[error("failed to get node features")]
51	CanceledNodeFeatures(#[source] oneshot::Canceled),
52
53	#[error("failed to get backed candidates")]
54	CanceledBackedCandidates(#[source] oneshot::Canceled),
55
56	#[error("failed to get votes on dispute")]
57	CanceledCandidateVotes(#[source] oneshot::Canceled),
58
59	#[error("failed to get backable candidates from prospective parachains")]
60	CanceledBackableCandidates(#[source] oneshot::Canceled),
61
62	#[error(transparent)]
63	ChainApi(#[from] ChainApiError),
64
65	#[error(transparent)]
66	RuntimeApi(#[from] RuntimeApiError),
67
68	#[error("failed to send message to ChainAPI")]
69	ChainApiMessageSend(#[source] mpsc::SendError),
70
71	#[error("failed to send message to CandidateBacking to get backed candidates")]
72	GetBackedCandidatesSend(#[source] mpsc::SendError),
73
74	#[error("Send inherent data timeout.")]
75	SendInherentDataTimeout,
76
77	#[error("failed to send return message with Inherents")]
78	InherentDataReturnChannel,
79
80	#[fatal]
81	#[error("Failed to spawn background task")]
82	FailedToSpawnBackgroundTask,
83
84	#[error(transparent)]
85	SubsystemError(#[from] SubsystemError),
86
87	#[fatal]
88	#[error(transparent)]
89	OverseerExited(SubsystemError),
90}
91
92/// Used by `get_onchain_disputes` to represent errors related to fetching on-chain disputes from
93/// the Runtime
94#[allow(dead_code)] // Remove when promoting to stable
95#[fatality::fatality]
96pub enum GetOnchainDisputesError {
97	#[fatal]
98	#[error("runtime subsystem is down")]
99	Channel,
100
101	#[error("runtime execution error occurred while fetching onchain disputes for parent {1}")]
102	Execution(#[source] RuntimeApiError, Hash),
103
104	#[error("runtime doesn't support RuntimeApiRequest::Disputes for parent {1}")]
105	NotSupported(#[source] RuntimeApiError, Hash),
106}
107
108pub fn log_error(result: Result<()>) -> std::result::Result<(), FatalError> {
109	match result.into_nested()? {
110		Ok(()) => Ok(()),
111		Err(jfyi) => {
112			jfyi.log();
113			Ok(())
114		},
115	}
116}
117
118impl JfyiError {
119	/// Log a `JfyiError`.
120	pub fn log(self) {
121		gum::debug!(target: super::LOG_TARGET, error = ?self);
122	}
123}