referrerpolicy=no-referrer-when-downgrade

polkadot_node_core_prospective_parachains/
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.
18
19use futures::channel::oneshot;
20
21use polkadot_node_subsystem::{
22	errors::{ChainApiError, RuntimeApiError},
23	SubsystemError,
24};
25use polkadot_node_subsystem_util::runtime;
26
27use crate::LOG_TARGET;
28use fatality::Nested;
29
30#[allow(missing_docs)]
31#[fatality::fatality(splitable)]
32pub enum Error {
33	#[fatal]
34	#[error("Receiving message from overseer failed: {0}")]
35	SubsystemReceive(#[source] SubsystemError),
36
37	#[error("Error while accessing runtime information")]
38	Runtime(#[from] runtime::Error),
39
40	#[error(transparent)]
41	RuntimeApi(#[from] RuntimeApiError),
42
43	#[error(transparent)]
44	ChainApi(#[from] ChainApiError),
45
46	#[error("Request to chain API subsystem dropped")]
47	ChainApiRequestCanceled(oneshot::Canceled),
48
49	#[error("Request to runtime API subsystem dropped")]
50	RuntimeApiRequestCanceled(oneshot::Canceled),
51}
52
53/// General `Result` type.
54pub type Result<R> = std::result::Result<R, Error>;
55/// Result for non-fatal only failures.
56pub type JfyiErrorResult<T> = std::result::Result<T, JfyiError>;
57/// Result for fatal only failures.
58pub type FatalResult<T> = std::result::Result<T, FatalError>;
59
60/// Utility for eating top level errors and log them.
61///
62/// We basically always want to try and continue on error. This utility function is meant to
63/// consume top-level errors by simply logging them
64pub fn log_error(result: Result<()>, ctx: &'static str) -> FatalResult<()> {
65	match result.into_nested()? {
66		Ok(()) => Ok(()),
67		Err(jfyi) => {
68			gum::debug!(target: LOG_TARGET, error = ?jfyi, ctx);
69			Ok(())
70		},
71	}
72}