use std::ffi::NulError;
use super::EngineType;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum LimitKind {
Operations,
CallDepth,
String,
Array,
Map,
Source,
}
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("engine mutex poisoned")]
MutexPoisoned,
#[error("rhai error: {0}")]
Rhai(String),
#[error("python error: {0}")]
Python(String),
#[error("resource exhausted ({kind:?}) on {backend:?} engine")]
ResourceExhausted {
backend: EngineType,
kind: LimitKind,
},
#[error("{limit} not supported on {backend:?} engine")]
LimitUnsupported {
backend: EngineType,
limit: &'static str,
},
#[error("value not convertible to JSON on {backend:?} engine")]
UnconvertibleValue { backend: EngineType },
#[error("invalid variable name: {0}")]
InvalidName(String),
#[error("expression validation failed: {0}")]
ValidationFailed(ValidationError),
#[error("invalid function name: {0}")]
FunctionName(#[from] NulError),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ExprIssueKind {
Syntax,
UnknownRoot,
DynamicEval,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ExprIssue {
pub locator: String,
pub message: String,
pub kind: ExprIssueKind,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ValidationError(pub Vec<ExprIssue>);
impl std::fmt::Display for ValidationError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let kinds = self
.0
.iter()
.map(|issue| format!("{:?}: {}", issue.kind, issue.message))
.collect::<Vec<_>>()
.join("; ");
write!(f, "{} issue(s): {kinds}", self.0.len())
}
}