referrerpolicy=no-referrer-when-downgrade

polkadot_dispute_distribution/
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 polkadot_node_subsystem::SubsystemError;
21use polkadot_node_subsystem_util::runtime;
22
23use crate::{sender, LOG_TARGET};
24
25use fatality::Nested;
26
27#[allow(missing_docs)]
28#[fatality::fatality(splitable)]
29pub enum Error {
30	/// Receiving subsystem message from overseer failed.
31	#[fatal]
32	#[error("Receiving message from overseer failed")]
33	SubsystemReceive(#[source] SubsystemError),
34
35	/// Spawning a running task failed.
36	#[fatal]
37	#[error("Spawning subsystem task failed")]
38	SpawnTask(#[source] SubsystemError),
39
40	/// `DisputeSender` mpsc receiver exhausted.
41	#[fatal]
42	#[error("Erasure chunk requester stream exhausted")]
43	SenderExhausted,
44
45	/// Errors coming from `runtime::Runtime`.
46	#[fatal(forward)]
47	#[error("Error while accessing runtime information")]
48	Runtime(#[from] runtime::Error),
49
50	/// Errors coming from `DisputeSender`
51	#[fatal(forward)]
52	#[error("Error while accessing runtime information")]
53	Sender(#[from] sender::Error),
54}
55
56pub type Result<T> = std::result::Result<T, Error>;
57
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) -> std::result::Result<(), FatalError> {
65	match result.into_nested()? {
66		Err(jfyi) => {
67			gum::warn!(target: LOG_TARGET, error = ?jfyi, ctx);
68			Ok(())
69		},
70		Ok(()) => Ok(()),
71	}
72}