This repository has been archived on 2026-09-15. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
OxideJS/crates/oxide_parser/src/error.rs
T
2026-06-05 01:29:24 +08:00

31 lines
739 B
Rust

use std::fmt;
#[derive(Debug, Clone)]
pub struct OxideError {
pub message: String,
pub span: (usize, usize),
}
impl fmt::Display for OxideError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{} at {:?}", self.message, self.span)
}
}
impl std::error::Error for OxideError {}
impl From<oxc_diagnostics::OxcDiagnostic> for OxideError {
fn from(diag: oxc_diagnostics::OxcDiagnostic) -> Self {
let span = diag
.labels
.clone()
.and_then(|labels| labels.first().map(|l| (l.offset(), l.offset() + l.len())))
.unwrap_or((0, 0));
OxideError {
message: diag.message.to_string(),
span,
}
}
}