use crate::seam::SeamError;
use crate::temporal::arithmetic::ArithmeticError;
#[derive(Debug, thiserror::Error)]
pub enum EvalError {
#[error("{operation} expects a single item, the collection holds {count}")]
Singleton {
operation: String,
count: usize,
},
#[error("{operation} does not apply to {found}")]
Type {
operation: String,
found: String,
},
#[error("the function {name}() is not defined")]
UnknownFunction {
name: String,
},
#[error("{function}() takes {expected} argument(s), {found} given")]
Arity {
function: String,
expected: &'static str,
found: usize,
},
#[error("{type_name} has no element {element}")]
UnknownElement {
type_name: String,
element: String,
},
#[error("the expression names the type {named}, the context is a {context}")]
ContextType {
named: String,
context: String,
},
#[error("{name} names no type of the model")]
UnknownType {
name: String,
},
#[error("the environment variable %{name} is not defined")]
UnknownVariable {
name: String,
},
#[error("{function}() needs a seam the environment does not supply")]
NoSeam {
function: &'static str,
},
#[error("the seam behind {function}() failed")]
Seam {
function: &'static str,
#[source]
source: SeamError,
},
#[error("the regular expression {pattern:?} does not compile")]
Regex {
pattern: String,
#[source]
source: regex::Error,
},
#[error("date and time arithmetic failed")]
Arithmetic {
#[source]
source: ArithmeticError,
},
#[error("the element {element} contradicts the model: {reason}")]
Document {
element: String,
reason: String,
},
#[error("the element carries the modifier extension {url}, which the call does not admit")]
Modifier {
url: String,
},
#[error(
"{operation} needs an ordered input, and the order of a collection derived from children() or descendants() is undefined"
)]
Unordered {
operation: String,
},
#[error("{function}() received an invalid argument: {reason}")]
Argument {
function: String,
reason: String,
},
}
impl EvalError {
pub(crate) fn type_error(operation: impl Into<String>, found: impl Into<String>) -> Self {
Self::Type {
operation: operation.into(),
found: found.into(),
}
}
pub(crate) fn singleton(operation: impl Into<String>, count: usize) -> Self {
Self::Singleton {
operation: operation.into(),
count,
}
}
}