referrerpolicy=no-referrer-when-downgrade

polkadot_availability_recovery/
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//! The `Error` and `Result` types used by the subsystem.
18
19use crate::LOG_TARGET;
20use fatality::{fatality, Nested};
21use futures::channel::oneshot;
22use polkadot_node_network_protocol::request_response::incoming;
23use polkadot_node_subsystem::{RecoveryError, SubsystemError};
24use polkadot_primitives::Hash;
25
26/// Error type used by the Availability Recovery subsystem.
27#[fatality(splitable)]
28pub enum Error {
29	#[fatal]
30	#[error("Spawning subsystem task failed: {0}")]
31	SpawnTask(#[source] SubsystemError),
32
33	/// Receiving subsystem message from overseer failed.
34	#[fatal]
35	#[error("Receiving message from overseer failed: {0}")]
36	SubsystemReceive(#[source] SubsystemError),
37
38	#[fatal]
39	#[error("failed to query full data from store")]
40	CanceledQueryFullData(#[source] oneshot::Canceled),
41
42	#[error("`SessionInfo` is `None` at {0}")]
43	SessionInfoUnavailable(Hash),
44
45	#[error("failed to query node features from runtime")]
46	RequestNodeFeatures(#[source] polkadot_node_subsystem_util::runtime::Error),
47
48	#[error("failed to send response")]
49	CanceledResponseSender,
50
51	#[error(transparent)]
52	Runtime(#[from] polkadot_node_subsystem::errors::RuntimeApiError),
53
54	#[error(transparent)]
55	Erasure(#[from] polkadot_erasure_coding::Error),
56
57	#[fatal]
58	#[error(transparent)]
59	Oneshot(#[from] oneshot::Canceled),
60
61	#[fatal(forward)]
62	#[error("Error during recovery: {0}")]
63	Recovery(#[from] RecoveryError),
64
65	#[fatal(forward)]
66	#[error("Retrieving next incoming request failed: {0}")]
67	IncomingRequest(#[from] incoming::Error),
68}
69
70pub type Result<T> = std::result::Result<T, Error>;
71
72/// Utility for eating top level errors and log them.
73///
74/// We basically always want to try and continue on error, unless the error is fatal for the entire
75/// subsystem.
76pub fn log_error(result: Result<()>) -> std::result::Result<(), FatalError> {
77	match result.into_nested()? {
78		Ok(()) => Ok(()),
79		Err(jfyi) => {
80			jfyi.log();
81			Ok(())
82		},
83	}
84}
85
86impl JfyiError {
87	/// Log a `JfyiError`.
88	pub fn log(self) {
89		gum::warn!(target: LOG_TARGET, "{}", self);
90	}
91}