use crate::mir::codegen::FromIRError;
use crate::mir_codegen::CodegenError;
use std::error::Error;
use std::fmt;
use std::string::FromUtf8Error;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum LaminaError {
ParsingError(String),
CodegenError(CodegenError),
MirError(String),
ValidationError(String),
IoError(String),
Utf8Error(String),
InternalError(String),
}
impl fmt::Display for LaminaError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
LaminaError::ParsingError(msg) => write!(f, "Parsing Error: {}", msg),
LaminaError::CodegenError(msg) => write!(f, "Codegen Error: {}", msg),
LaminaError::MirError(msg) => write!(f, "MIR Error: {}", msg),
LaminaError::ValidationError(msg) => write!(f, "Validation Error: {}", msg),
LaminaError::IoError(msg) => write!(f, "IO Error: {}", msg),
LaminaError::Utf8Error(msg) => write!(f, "UTF8 Error: {}", msg),
LaminaError::InternalError(msg) => write!(f, "Internal Error: {}", msg),
}
}
}
impl Error for LaminaError {}
impl From<std::io::Error> for LaminaError {
fn from(err: std::io::Error) -> Self {
LaminaError::IoError(err.to_string())
}
}
impl From<FromUtf8Error> for LaminaError {
fn from(err: FromUtf8Error) -> Self {
LaminaError::Utf8Error(err.to_string())
}
}
impl From<CodegenError> for LaminaError {
fn from(err: CodegenError) -> Self {
LaminaError::CodegenError(err)
}
}
impl From<FromIRError> for LaminaError {
fn from(err: FromIRError) -> Self {
LaminaError::MirError(format!("{}", err))
}
}