use cranelift_codegen::CodegenError;
use cranelift_module::ModuleError;
use evalexpr::{DefaultNumericTypes, EvalexprError};
use thiserror::Error;
#[derive(Error, Debug)]
pub enum ConvertError {
#[error("Could not convert exponent in Exp operator: {0}")]
ExpOperator(String),
#[error("Unsupported operator: {0}")]
UnsupportedOperator(String),
#[error("Unsupported function: {0}")]
UnsupportedFunction(String),
#[error("Expected single child for root node: {0}")]
RootNode(String),
#[error("Expected float constant: {0}")]
ConstOperator(String),
#[error("Variable not found: {0}")]
VariableNotFound(String),
}
#[derive(Error, Debug)]
pub enum BuilderError {
#[error("host machine is not supported: {0}")]
HostMachineNotSupported(String),
#[error("codegen error: {0}")]
CodegenError(CodegenError),
#[error("module error: {0}")]
ModuleError(ModuleError),
#[error("function error: {0}")]
FunctionError(String),
#[error("declaration error: {0}")]
DeclarationError(String),
}
#[derive(Debug, Error)]
pub enum EquationError {
#[error("Failed to build Evalexpr AST")]
BuildEvalexprError(#[from] EvalexprError<DefaultNumericTypes>),
#[error("Failed to build JIT AST")]
BuildJITError(#[from] ConvertError),
#[error("Failed to build JIT function")]
BuildFunctionError(#[from] BuilderError),
#[error("Derivative not found for variable: {0}")]
DerivativeNotFound(String),
#[error("Invalid input length: expected {expected}, got {got}")]
InvalidInputLength { expected: usize, got: usize },
#[error("Variable not found in equation: {0}")]
VariableNotFound(String),
#[error("Invalid output length: expected {expected}, got {got}")]
InvalidOutputLength { expected: usize, got: usize },
#[error("Matrix output required: Got vector output for this system")]
MatrixOutputRequired,
#[error("Invalid matrix dimensions: expected {expected_rows}x{expected_cols}, got {got_rows}x{got_cols}")]
InvalidMatrixDimensions {
expected_rows: usize,
expected_cols: usize,
got_rows: usize,
got_cols: usize,
},
}