use ecma_lex_cat::error::Error as LexError;
use ecma_parse_cat::Error as ParseError;
use ecma_syntax_cat::error::Error as SyntaxError;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Error {
Lex(LexError),
Parse(Box<ParseError>),
Syntax(SyntaxError),
FuelExhausted {
limit: u64,
},
UncaughtException {
rendered: String,
},
Unsupported {
feature: &'static str,
},
BigIntUnsupported,
}
impl From<LexError> for Error {
fn from(value: LexError) -> Self {
Self::Lex(value)
}
}
impl From<ParseError> for Error {
fn from(value: ParseError) -> Self {
Self::Parse(Box::new(value))
}
}
impl From<SyntaxError> for Error {
fn from(value: SyntaxError) -> Self {
Self::Syntax(value)
}
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Lex(e) => write!(f, "lex error: {e}"),
Self::Parse(e) => write!(f, "parse error: {e}"),
Self::Syntax(e) => write!(f, "syntax error: {e}"),
Self::FuelExhausted { limit } => {
write!(f, "fuel exhausted after {limit} evaluation steps")
}
Self::UncaughtException { rendered } => {
write!(f, "uncaught exception: {rendered}")
}
Self::Unsupported { feature } => write!(f, "unsupported feature: {feature}"),
Self::BigIntUnsupported => f.write_str("BigInt evaluation is not implemented in v0"),
}
}
}
impl std::error::Error for Error {}