Skip to main content

jsxbin_parser/
error.rs

1use thiserror::Error;
2
3/// Parser error types
4#[derive(Error, Debug)]
5pub enum ParserError {
6    #[error("Invalid magic bytes: expected 0x4A 0x58, got {0:02x} {1:02x}")]
7    InvalidMagic(u8, u8),
8
9    #[error("Unsupported version: {0}")]
10    UnsupportedVersion(u32),
11
12    #[error("Unexpected end of file at offset {0}")]
13    UnexpectedEof(usize),
14
15    #[error("Invalid token at offset {offset}: {message}")]
16    InvalidToken { offset: usize, message: String },
17
18    #[error("Parse error at offset {offset}: {message}")]
19    ParseError { offset: usize, message: String },
20
21    #[error("Invalid string index: {0}")]
22    InvalidStringIndex(usize),
23
24    #[error("Malformed structure: {0}")]
25    MalformedStructure(String),
26
27    #[error("IO error: {0}")]
28    IoError(String),
29}
30
31impl From<std::io::Error> for ParserError {
32    fn from(err: std::io::Error) -> Self {
33        ParserError::IoError(err.to_string())
34    }
35}
36
37/// Result type for parser operations
38pub type ParserResult<T> = Result<T, ParserError>;