1#[derive(Debug, thiserror::Error)]
5pub enum Error {
6    #[error("{0}")]
8    Anyhow(#[from] anyhow::Error),
9    #[error(transparent)]
11    Abi(#[from] zabi::result::Error),
12    #[error(transparent)]
14    BinaryReader(#[from] wasmparser::BinaryReaderError),
15    #[error("Buffer overflow: {0}, the limit of the binary buffer is 0x6000.")]
17    BufferOverflow(usize),
18    #[error("Control stack underflow")]
20    ControlStackUnderflow,
21    #[error("Data not found in data setction, offset {0}, size {1}")]
23    DataNotFound(i32, usize),
24    #[error("Function {0} already exists in jump table")]
26    DuplicateFunc(u32),
27    #[error("Program counter {0} already exists in jump table")]
29    DuplicateJump(u16),
30    #[error("External function not found in jump table")]
32    ExtFuncNotFound,
33    #[error("Function {0} not found in jump table")]
35    FuncNotFound(u32),
36    #[error("Function {0} not imported")]
38    FuncNotImported(String),
39    #[error("Host function {0}::{1} not found in compiler")]
41    HostFuncNotFound(String, String),
42    #[error("Imported Function {0} not found in jump table")]
44    ImportedFuncNotFound(u32),
45    #[error("Invalid else block for if block at {0}")]
47    InvalidElseBlock(u16),
48    #[error("Invalid function signature")]
50    InvalidFunctionSignature,
51    #[error("Invalid local index {0}")]
53    InvalidLocalIndex(usize),
54    #[error("Invalid memory pointer {0}")]
56    InvalidMP(u8),
57    #[error("Invalid program counter {0}")]
59    InvalidPC(usize),
60    #[error("Invalid data offset {0}")]
62    InvalidDataOffset(i32),
63    #[error("Invalid data size {0}")]
65    InvalidDataSize(usize),
66    #[error("Invalid contract stack frame depth {0}")]
68    InvalidDepth(usize),
69    #[error("Invalid function selector")]
71    InvalidSelector,
72    #[error("Invalid frame label")]
74    LabelMismatch,
75    #[error("Local index in function is out of range")]
77    LocalIndexOutOfRange,
78    #[error("Local variable {0} is not on stack")]
80    LocalNotOnStack(usize),
81    #[error("Memory index is out of range")]
83    MemoryOutOfBounds,
84    #[error("Function selector is not found.")]
86    SelectorNotFound,
87    #[error("Stack index is out of range {0}, max is 255 (0x400)")]
89    StackIndexOutOfRange(u16),
90    #[error("Stack overflow, max is 1024 stack items, but add {1} to {0}")]
92    StackOverflow(u16, u16),
93    #[error("Stack underflow, current stack items {0}, expect at least {1}")]
95    StackUnderflow(u16, u16),
96    #[error("Stack not balanced, current stack items {0}")]
98    StackNotBalanced(u16),
99    #[error("Unsupported host function {0:?}")]
101    UnsupportedHostFunc(crate::wasm::HostFunc),
102}
103
104pub type Result<T> = std::result::Result<T, Error>;