polkadot_availability_distribution/
error.rs1use fatality::Nested;
21use polkadot_node_network_protocol::request_response::outgoing::RequestError;
22use polkadot_primitives::SessionIndex;
23
24use futures::channel::oneshot;
25
26use polkadot_node_subsystem::{ChainApiError, RuntimeApiError, SubsystemError};
27use polkadot_node_subsystem_util::runtime;
28
29use crate::LOG_TARGET;
30
31#[allow(missing_docs)]
32#[fatality::fatality(splitable)]
33pub enum Error {
34 #[fatal]
35 #[error("Spawning subsystem task failed: {0}")]
36 SpawnTask(#[source] SubsystemError),
37
38 #[fatal]
39 #[error("Erasure chunk requester stream exhausted")]
40 RequesterExhausted,
41
42 #[fatal]
43 #[error("Receive channel closed: {0}")]
44 IncomingMessageChannel(#[source] SubsystemError),
45
46 #[fatal(forward)]
47 #[error("Error while accessing runtime information: {0}")]
48 Runtime(#[from] runtime::Error),
49
50 #[fatal]
51 #[error("Oneshot for receiving response from Chain API got cancelled")]
52 ChainApiSenderDropped(#[from] oneshot::Canceled),
53
54 #[fatal]
55 #[error("Retrieving response from Chain API unexpectedly failed with error: {0}")]
56 ChainApi(#[from] ChainApiError),
57
58 #[error("Failed to get node features from the runtime")]
59 FailedNodeFeatures(#[source] RuntimeApiError),
60
61 #[error("Response channel to obtain chunk failed")]
63 QueryChunkResponseChannel(#[source] oneshot::Canceled),
64
65 #[error("Response channel to obtain available data failed")]
67 QueryAvailableDataResponseChannel(#[source] oneshot::Canceled),
68
69 #[error("Session {missing_session} is not cached, cached sessions: {available_sessions:?}.")]
71 NoSuchCachedSession { available_sessions: Vec<SessionIndex>, missing_session: SessionIndex },
72
73 #[error("Sending a request's response failed.")]
75 SendResponse,
76
77 #[error("FetchPoV request error: {0}")]
78 FetchPoV(#[source] RequestError),
79
80 #[error("Fetched PoV does not match expected hash")]
81 UnexpectedPoV,
82
83 #[error("Remote responded with `NoSuchPoV`")]
84 NoSuchPoV,
85
86 #[error("Given validator index could not be found in current session")]
87 InvalidValidatorIndex,
88
89 #[error("Erasure coding error: {0}")]
90 ErasureCoding(#[from] polkadot_erasure_coding::Error),
91}
92
93pub type Result<T> = std::result::Result<T, Error>;
95
96pub fn log_error(
101 result: Result<()>,
102 ctx: &'static str,
103 warn_freq: &mut gum::Freq,
104) -> std::result::Result<(), FatalError> {
105 match result.into_nested()? {
106 Ok(()) => Ok(()),
107 Err(jfyi) => {
108 match jfyi {
109 JfyiError::UnexpectedPoV |
110 JfyiError::InvalidValidatorIndex |
111 JfyiError::NoSuchCachedSession { .. } |
112 JfyiError::QueryAvailableDataResponseChannel(_) |
113 JfyiError::QueryChunkResponseChannel(_) |
114 JfyiError::FailedNodeFeatures(_) |
115 JfyiError::ErasureCoding(_) => gum::warn!(target: LOG_TARGET, error = %jfyi, ctx),
116 JfyiError::FetchPoV(_) |
117 JfyiError::SendResponse |
118 JfyiError::NoSuchPoV |
119 JfyiError::Runtime(_) =>
120 gum::warn_if_frequent!(freq: warn_freq, max_rate: gum::Times::PerHour(100), target: LOG_TARGET, error = ?jfyi, ctx),
121 }
122 Ok(())
123 },
124 }
125}