use ::orchestra::OrchestraError as OverseerError;
use fatality::fatality;
#[derive(thiserror::Error, Debug, Clone)]
pub enum RuntimeApiError {
#[error("The runtime API '{runtime_api_name}' cannot be executed: {source}")]
Execution {
runtime_api_name: &'static str,
#[source]
source: std::sync::Arc<dyn 'static + std::error::Error + Send + Sync>,
},
#[error("The API is not supported by the runtime at the relay-parent")]
NotSupported {
runtime_api_name: &'static str,
},
}
#[derive(Debug, Clone)]
pub struct ChainApiError {
msg: String,
}
impl From<&str> for ChainApiError {
fn from(s: &str) -> Self {
s.to_owned().into()
}
}
impl From<String> for ChainApiError {
fn from(msg: String) -> Self {
Self { msg }
}
}
impl core::fmt::Display for ChainApiError {
fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
write!(f, "{}", self.msg)
}
}
impl std::error::Error for ChainApiError {}
#[derive(PartialEq, Clone)]
#[fatality(splitable)]
#[allow(missing_docs)]
pub enum RecoveryError {
#[error("Invalid data")]
Invalid,
#[error("Data is unavailable")]
Unavailable,
#[fatal]
#[error("Erasure task channel closed")]
ChannelClosed,
}
#[derive(thiserror::Error, Debug)]
#[allow(missing_docs)]
pub enum SubsystemError {
#[error(transparent)]
NotifyCancellation(#[from] futures::channel::oneshot::Canceled),
#[error(transparent)]
QueueError(#[from] futures::channel::mpsc::SendError),
#[error(transparent)]
Io(#[from] std::io::Error),
#[error(transparent)]
Infallible(#[from] std::convert::Infallible),
#[error(transparent)]
Prometheus(#[from] prometheus_endpoint::PrometheusError),
#[error("Failed to {0}")]
Context(String),
#[error("Subsystem stalled: {0}")]
SubsystemStalled(&'static str),
#[error(transparent)]
Generated(#[from] OverseerError),
#[error("Error originated in {origin}")]
FromOrigin {
origin: &'static str,
#[source]
source: Box<dyn 'static + std::error::Error + Send + Sync>,
},
}
impl SubsystemError {
pub fn with_origin<E: 'static + Send + Sync + std::error::Error>(
origin: &'static str,
err: E,
) -> Self {
Self::FromOrigin { origin, source: Box::new(err) }
}
}
pub type SubsystemResult<T> = Result<T, self::SubsystemError>;