use crate::value::ExceptionValue;
#[derive(Debug, Clone, thiserror::Error)]
#[non_exhaustive]
pub enum InterpreterError {
#[error("SyntaxError: {0}")]
Syntax(String),
#[error("SecurityError: {0}")]
Security(String),
#[error("RuntimeError: {0}")]
Runtime(String),
#[error("LimitExceeded: {0}")]
LimitExceeded(String),
#[error("RecursionError: maximum recursion depth exceeded ({limit})")]
RecursionLimitExceeded {
limit: u32,
},
#[error("ToolError in '{tool_name}': {message}")]
Tool { tool_name: String, message: String },
#[error("NameError: {0}")]
NameError(String),
#[error("TypeError: {0}")]
TypeError(String),
#[error("ValueError: {0}")]
ValueError(String),
#[error("AttributeError: {0}")]
AttributeError(String),
#[error("AssertionError: {0}")]
AssertionError(String),
#[error("{type_name}: {message}")]
PythonException { type_name: String, message: String },
#[error(
"interpreter state format superseded: found version {found}, expected {expected}; \
host must restart from initial step"
)]
StateFormatSuperseded {
found: u32,
expected: u32,
},
}
impl InterpreterError {
#[must_use]
pub fn name_not_defined(name: impl AsRef<str>) -> Self {
Self::NameError(format!("name '{}' is not defined", name.as_ref()))
}
}
#[derive(Debug, Clone)]
pub(crate) enum ControlFlow {
Break,
Continue,
Return(Box<crate::value::Value>),
}
#[derive(Debug, Clone)]
pub(crate) enum EvalError {
Interpreter(InterpreterError),
Signal(ControlFlow),
Exception(ExceptionValue),
}
impl From<InterpreterError> for EvalError {
fn from(e: InterpreterError) -> Self {
Self::Interpreter(e)
}
}
impl From<ExceptionValue> for EvalError {
fn from(e: ExceptionValue) -> Self {
Self::Exception(e)
}
}
pub(crate) type EvalResult = Result<crate::value::Value, EvalError>;