referrerpolicy=no-referrer-when-downgrade

polkadot_collator_protocol/collator_side/
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 polkadot_node_network_protocol::request_response::incoming;
18use polkadot_node_primitives::UncheckedSignedFullStatement;
19use polkadot_node_subsystem::{errors::SubsystemError, RuntimeApiError};
20use polkadot_node_subsystem_util::{backing_implicit_view, runtime};
21
22use crate::LOG_TARGET;
23
24/// General result.
25pub type Result<T> = std::result::Result<T, Error>;
26
27use fatality::Nested;
28
29#[allow(missing_docs)]
30#[fatality::fatality(splitable)]
31pub enum Error {
32	#[fatal]
33	#[error("Receiving message from overseer failed")]
34	SubsystemReceive(#[from] SubsystemError),
35
36	#[fatal(forward)]
37	#[error("Retrieving next incoming request failed")]
38	IncomingRequest(#[from] incoming::Error),
39
40	#[fatal(forward)]
41	#[error("Error while accessing runtime information")]
42	Runtime(#[from] runtime::Error),
43
44	#[error("Error while accessing Runtime API")]
45	RuntimeApi(#[from] RuntimeApiError),
46
47	#[error(transparent)]
48	ImplicitViewFetchError(backing_implicit_view::FetchError),
49
50	#[error("CollationSeconded contained statement with invalid signature")]
51	InvalidStatementSignature(UncheckedSignedFullStatement),
52}
53
54/// Utility for eating top level errors and log them.
55///
56/// We basically always want to try and continue on error. This utility function is meant to
57/// consume top-level errors by simply logging them.
58pub fn log_error(result: Result<()>, ctx: &'static str) -> std::result::Result<(), FatalError> {
59	match result.into_nested()? {
60		Ok(()) => Ok(()),
61		Err(jfyi) => {
62			gum::warn!(target: LOG_TARGET, error = ?jfyi, ctx);
63			Ok(())
64		},
65	}
66}