use std::fmt;
use std::sync::Arc;
#[derive(Clone, Debug)]
pub struct StoreError {
op: &'static str,
inner: Arc<datumesh_store::Error>,
}
impl StoreError {
pub(crate) fn new(op: &'static str, e: datumesh_store::Error) -> StoreError {
StoreError { op, inner: Arc::new(e) }
}
pub fn operation(&self) -> &str {
self.op
}
pub fn store_error(&self) -> &datumesh_store::Error {
&self.inner
}
pub fn is_conflict(&self) -> bool {
matches!(*self.inner, datumesh_store::Error::Conflict { .. })
}
}
impl fmt::Display for StoreError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &*self.inner {
datumesh_store::Error::Conflict { hash } => write!(
f,
"store {}: another receipt is already recorded where receipt {hash} was to go; the recorded one is kept",
self.op
),
other => write!(f, "store {}: {other}", self.op),
}
}
}
impl std::error::Error for StoreError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
Some(&*self.inner)
}
}
#[non_exhaustive]
#[derive(Clone, Debug)]
pub enum EvalError {
NoRuntime {
lang: String,
},
UndeclaredInput {
fn_name: String,
},
Cycle {
cell_id: String,
},
DepthExceeded {
limit: usize,
},
BudgetExceeded {
fuel: u64,
},
NameUnresolved {
fn_name: String,
asof: String,
},
Store(StoreError),
Runtime(String),
Suspended,
InputNotCovered {
cell_id: String,
},
InvalidInput(datumesh_core::Error),
Fault(datumesh_core::Fault),
BlobUnavailable {
sha256: String,
reason: String,
},
}
impl fmt::Display for EvalError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
EvalError::NoRuntime { lang } => write!(f, "no runtime for language {lang}"),
EvalError::UndeclaredInput { fn_name } => write!(f, "{fn_name} is not a declared input"),
EvalError::Cycle { cell_id } => write!(f, "cycle: cell {cell_id} depends on itself"),
EvalError::DepthExceeded { limit } => write!(f, "evaluation deeper than the limit of {limit}"),
EvalError::BudgetExceeded { fuel } => write!(f, "evaluation needs more than its fuel of {fuel}"),
EvalError::NameUnresolved { fn_name, asof } => write!(f, "{fn_name} has no binding as of {asof}"),
EvalError::Store(e) => e.fmt(f),
EvalError::Runtime(m) => write!(f, "runtime: {m}"),
EvalError::Suspended => f.write_str("evaluation suspended until an input is available"),
EvalError::InputNotCovered { cell_id } => write!(f, "input cell {cell_id} has no value as of the asof"),
EvalError::InvalidInput(e) => write!(f, "invalid input cell: {e}"),
EvalError::Fault(c) => write!(f, "evaluation fault {c}"),
EvalError::BlobUnavailable { sha256, reason } => {
write!(f, "the content of blob {sha256} is unavailable: {reason}")
}
}
}
}
impl std::error::Error for EvalError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
EvalError::Store(e) => Some(e),
EvalError::InvalidInput(e) => Some(e),
_ => None,
}
}
}
#[non_exhaustive]
#[derive(Clone, Debug)]
pub enum EngineError {
NoRuntime {
lang: String,
fn_hash: String,
},
UndeclaredInput {
fn_name: String,
},
Cycle {
cell_id: String,
},
DepthExceeded {
limit: usize,
},
BudgetExceeded {
fuel: u64,
},
WorkExceeded {
limit: u64,
},
NameUnresolved {
fn_name: String,
asof: String,
},
Store(StoreError),
Runtime {
cell_id: String,
message: String,
},
BlobUnavailable {
sha256: String,
reason: String,
},
Invalid(datumesh_core::Error),
Sign(datumesh_core::Error),
}
impl fmt::Display for EngineError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
EngineError::NoRuntime { lang, fn_hash } => {
write!(f, "no runtime for language {lang} (function {fn_hash})")
}
EngineError::UndeclaredInput { fn_name } => write!(f, "{fn_name} is not a declared input"),
EngineError::Cycle { cell_id } => write!(f, "cycle: cell {cell_id} depends on itself"),
EngineError::DepthExceeded { limit } => write!(f, "evaluation deeper than the limit of {limit}"),
EngineError::BudgetExceeded { fuel } => {
write!(f, "evaluation needs more than its fuel of {fuel}; nothing was stored")
}
EngineError::WorkExceeded { limit } => {
write!(f, "evaluation needs more work than its limit of {limit}; nothing was stored")
}
EngineError::NameUnresolved { fn_name, asof } => write!(f, "{fn_name} has no binding as of {asof}"),
EngineError::Store(e) => e.fmt(f),
EngineError::Runtime { cell_id, message } => write!(f, "runtime, evaluating cell {cell_id}: {message}"),
EngineError::BlobUnavailable { sha256, reason } => {
write!(f, "the content of blob {sha256} is unavailable: {reason}; nothing was stored")
}
EngineError::Invalid(e) => write!(f, "invalid request: {e}"),
EngineError::Sign(e) => write!(f, "cannot sign the computed receipt: {e}"),
}
}
}
impl std::error::Error for EngineError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
EngineError::Store(e) => Some(e),
EngineError::Invalid(e) | EngineError::Sign(e) => Some(e),
_ => None,
}
}
}
impl From<StoreError> for EngineError {
fn from(e: StoreError) -> EngineError {
EngineError::Store(e)
}
}
#[non_exhaustive]
#[derive(Debug)]
pub enum ConfigError {
Host(datumesh_core::Error),
NoSigningKey,
KeyFile(String),
Licence(datumesh_core::Error),
KeyNotPublished {
host: String,
key_id: String,
},
Store(StoreError),
Runtime(String),
}
impl fmt::Display for ConfigError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ConfigError::Host(e) => write!(f, "mesh host: {e}"),
ConfigError::NoSigningKey => f.write_str("no signing key"),
ConfigError::KeyFile(m) => write!(f, "signing key file: {m}"),
ConfigError::Licence(e) => write!(f, "licence: {e}"),
ConfigError::KeyNotPublished { host, key_id } => {
write!(f, "the store holds no key document of {host} publishing key {key_id}")
}
ConfigError::Store(e) => e.fmt(f),
ConfigError::Runtime(m) => write!(f, "runtimes: {m}"),
}
}
}
impl std::error::Error for ConfigError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
ConfigError::Host(e) | ConfigError::Licence(e) => Some(e),
ConfigError::Store(e) => Some(e),
_ => None,
}
}
}