use crate::LOG_TARGET;
use fatality::{fatality, Nested};
use futures::channel::oneshot;
use polkadot_node_network_protocol::request_response::incoming;
use polkadot_node_subsystem::{RecoveryError, SubsystemError};
use polkadot_primitives::Hash;
#[fatality(splitable)]
pub enum Error {
#[fatal]
#[error("Spawning subsystem task failed: {0}")]
SpawnTask(#[source] SubsystemError),
#[fatal]
#[error("Receiving message from overseer failed: {0}")]
SubsystemReceive(#[source] SubsystemError),
#[fatal]
#[error("failed to query full data from store")]
CanceledQueryFullData(#[source] oneshot::Canceled),
#[error("`SessionInfo` is `None` at {0}")]
SessionInfoUnavailable(Hash),
#[error("failed to query node features from runtime")]
RequestNodeFeatures(#[source] polkadot_node_subsystem_util::runtime::Error),
#[error("failed to send response")]
CanceledResponseSender,
#[error(transparent)]
Runtime(#[from] polkadot_node_subsystem::errors::RuntimeApiError),
#[error(transparent)]
Erasure(#[from] polkadot_erasure_coding::Error),
#[fatal]
#[error(transparent)]
Oneshot(#[from] oneshot::Canceled),
#[fatal(forward)]
#[error("Error during recovery: {0}")]
Recovery(#[from] RecoveryError),
#[fatal(forward)]
#[error("Retrieving next incoming request failed: {0}")]
IncomingRequest(#[from] incoming::Error),
}
pub type Result<T> = std::result::Result<T, Error>;
pub fn log_error(result: Result<()>) -> std::result::Result<(), FatalError> {
match result.into_nested()? {
Ok(()) => Ok(()),
Err(jfyi) => {
jfyi.log();
Ok(())
},
}
}
impl JfyiError {
pub fn log(self) {
gum::warn!(target: LOG_TARGET, "{}", self);
}
}