plotnik_lib/emit/
error.rs

1//! Error types for bytecode emission.
2
3use plotnik_core::Symbol;
4
5/// Error during bytecode emission.
6#[derive(Clone, Debug)]
7pub enum EmitError {
8    /// Query has validation errors (must be valid before emitting).
9    InvalidQuery,
10    /// Too many strings (exceeds u16 max).
11    TooManyStrings(usize),
12    /// Too many types (exceeds u16 max).
13    TooManyTypes(usize),
14    /// Too many type members (exceeds u16 max).
15    TooManyTypeMembers(usize),
16    /// Too many entrypoints (exceeds u16 max).
17    TooManyEntrypoints(usize),
18    /// Too many transitions (exceeds u16 max).
19    TooManyTransitions(usize),
20    /// String not found in interner.
21    StringNotFound(Symbol),
22    /// Compilation error.
23    Compile(crate::compile::CompileError),
24}
25
26impl std::fmt::Display for EmitError {
27    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28        match self {
29            Self::InvalidQuery => write!(f, "query has validation errors"),
30            Self::TooManyStrings(n) => write!(f, "too many strings: {n} (max 65534)"),
31            Self::TooManyTypes(n) => write!(f, "too many types: {n} (max 65533)"),
32            Self::TooManyTypeMembers(n) => write!(f, "too many type members: {n} (max 65535)"),
33            Self::TooManyEntrypoints(n) => write!(f, "too many entrypoints: {n} (max 65535)"),
34            Self::TooManyTransitions(n) => write!(f, "too many transitions: {n} (max 65535)"),
35            Self::StringNotFound(sym) => write!(f, "string not found for symbol: {sym:?}"),
36            Self::Compile(e) => write!(f, "compilation error: {e}"),
37        }
38    }
39}
40
41impl std::error::Error for EmitError {}