#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error(transparent)]
BinaryReader(#[from] wasmparser::BinaryReaderError),
#[error("Buffer overflow: {0}, the limit of the binary buffer is 0x6000.")]
BufferOverflow(usize),
#[error("Control stack underflow")]
ControlStackUnderflow,
#[error("Function {0} already exists in jump table")]
DuplicateFunc(u32),
#[error("Program counter {0} already exists in jump table")]
DuplicateJump(u16),
#[error("Imported Function {0} not found in jump table")]
ImportedFuncNotFound(u32),
#[error("Function {0} not found in jump table")]
FuncNotFound(u32),
#[error("External function {0:?} not found in jump table")]
ExtNotFound(crate::Func),
#[error("Invalid else block for if block at {0}")]
InvalidElseBlock(u16),
#[error("Invalid local index {0}")]
InvalidLocalIndex(usize),
#[error("Invalid memory pointer {0}")]
InvalidMP(u8),
#[error("Invalid program counter {0}")]
InvalidPC(usize),
#[error("Invalid contract stack fram depth {0}")]
InvalidDepth(usize),
#[error("Invalid frame label")]
LabelMismatch,
#[error("Local index in function is out of range")]
LocalIndexOutOfRange,
#[error("Local variable {0} is not on stack")]
LocalNotOnStack(usize),
#[error("Memory index is out of range")]
MemoryOutOfBounds,
#[error("Stack index is out of range {0}, max is 32 (0x400)")]
StackIndexOutOfRange(u8),
#[error("Stack overflow, max is 12 stack items, got {0}")]
StackOverflow(u8),
#[error("Stack underflow, current stack items {0}, expect at least {1}")]
StackUnderflow(u8, u8),
#[error("Stack not balanced, current stack items {0}")]
StackNotBalanced(u8),
}
pub type Result<T> = std::result::Result<T, Error>;