referrerpolicy=no-referrer-when-downgrade

polkadot_collator_protocol/validator_side_experimental/
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
17use crate::LOG_TARGET;
18use fatality::Nested;
19use polkadot_node_subsystem::{ChainApiError, SubsystemError};
20use polkadot_node_subsystem_util::runtime;
21use polkadot_primitives::Hash;
22
23pub type Result<T> = std::result::Result<T, Error>;
24pub type FatalResult<T> = std::result::Result<T, FatalError>;
25
26#[fatality::fatality(splitable)]
27pub enum Error {
28	#[fatal]
29	#[error("Oneshot for receiving ancestors from chain API got cancelled")]
30	CanceledAncestors,
31	#[fatal]
32	#[error("Oneshot for receiving finalized block number from chain API got cancelled")]
33	CanceledFinalizedBlockNumber,
34	#[fatal]
35	#[error("Oneshot for receiving finalized block hash from chain API got cancelled")]
36	CanceledFinalizedBlockHash,
37	#[error("Finalized block hash for {0} not found")]
38	FinalizedBlockNotFound(u32),
39	#[error(transparent)]
40	ChainApi(#[from] ChainApiError),
41	#[fatal(forward)]
42	#[error("Error while accessing runtime information {0}")]
43	Runtime(#[from] runtime::Error),
44	#[fatal]
45	#[error("Receiving message from overseer failed: {0}")]
46	SubsystemReceive(#[source] SubsystemError),
47}
48
49/// Utility for eating top level errors and log them.
50///
51/// We basically always want to try and continue on error. This utility function is meant to
52/// consume top-level errors by simply logging them
53pub fn log_error(result: Result<()>) -> FatalResult<()> {
54	match result.into_nested()? {
55		Ok(()) => Ok(()),
56		Err(jfyi) => {
57			jfyi.log();
58			Ok(())
59		},
60	}
61}
62
63impl JfyiError {
64	/// Log a `JfyiError`.
65	pub fn log(self) {
66		gum::warn!(target: LOG_TARGET, error = ?self);
67	}
68}