referrerpolicy=no-referrer-when-downgrade

polkadot_node_subsystem_util/runtime/
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
18//! Error handling related code and Error/Result definitions.
19
20use futures::channel::oneshot;
21
22use polkadot_node_subsystem::errors::RuntimeApiError;
23use polkadot_primitives::SessionIndex;
24
25#[allow(missing_docs)]
26#[fatality::fatality(splitable)]
27pub enum Error {
28	/// Runtime API subsystem is down, which means we're shutting down.
29	#[fatal]
30	#[error("Runtime request got canceled")]
31	RuntimeRequestCanceled(#[from] oneshot::Canceled),
32
33	/// Some request to the runtime failed.
34	/// For example if we prune a block we're requesting info about.
35	#[error("Runtime API error {0}")]
36	RuntimeRequest(#[from] RuntimeApiError),
37
38	/// We tried fetching a session info which was not available.
39	#[error("There was no session with the given index {0}")]
40	NoSuchSession(SessionIndex),
41
42	/// We tried fetching executor params for a session which were not available.
43	#[error("There was no executor parameters for session with the given index {0}")]
44	NoExecutorParams(SessionIndex),
45}
46
47pub type Result<T> = std::result::Result<T, Error>;
48
49/// Receive a response from a runtime request and convert errors.
50pub async fn recv_runtime<V>(
51	r: oneshot::Receiver<std::result::Result<V, RuntimeApiError>>,
52) -> Result<V> {
53	let result = r
54		.await
55		.map_err(FatalError::RuntimeRequestCanceled)?
56		.map_err(JfyiError::RuntimeRequest)?;
57	Ok(result)
58}