summaryrefslogtreecommitdiff
path: root/crates/parser/src/error.rs
blob: c99fa01203062e45c467feb46fbeebde4238e707 (plain)
use alloc::string::{String, ToString};
use wasmparser::Encoding;

pub enum ParseError {
    UnsupportedSection(String),
    DuplicateSection(String),
    EmptySection(String),
    UnsupportedOperator(String),
    ParseError { message: String, offset: usize },
    InvalidEncoding(Encoding),
    InvalidLocalCount { expected: u32, actual: u32 },
    EndNotReached,
    Other(String),
}

impl From<wasmparser::BinaryReaderError> for ParseError {
    fn from(value: wasmparser::BinaryReaderError) -> Self {
        Self::ParseError {
            message: value.message().to_string(),
            offset: value.offset(),
        }
    }
}

pub type Result<T, E = ParseError> = core::result::Result<T, E>;