#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("{0}")]
Anyhow(#[from] anyhow::Error),
#[error(transparent)]
Abi(#[from] zabi::result::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("Data not found in data setction, offset {0}, size {1}")]
DataNotFound(i32, usize),
#[error("Function {0} already exists in jump table")]
DuplicateFunc(u32),
#[error("Program counter {0} already exists in jump table")]
DuplicateJump(u16),
#[error("External function not found in jump table")]
ExtFuncNotFound,
#[error("Function {0} not found in jump table")]
FuncNotFound(u32),
#[error("Function {0} not imported")]
FuncNotImported(String),
#[error("Host function {0}::{1} not found in compiler")]
HostFuncNotFound(String, String),
#[error("Imported Function {0} not found in jump table")]
ImportedFuncNotFound(u32),
#[error("Invalid else block for if block at {0}")]
InvalidElseBlock(u16),
#[error("Invalid function signature")]
InvalidFunctionSignature,
#[error("Invalid local index {0}")]
InvalidLocalIndex(usize),
#[error("Invalid memory pointer {0}")]
InvalidMP(u8),
#[error("Invalid program counter {0}")]
InvalidPC(usize),
#[error("Invalid data offset {0}")]
InvalidDataOffset(i32),
#[error("Invalid data size {0}")]
InvalidDataSize(usize),
#[error("Invalid contract stack frame depth {0}")]
InvalidDepth(usize),
#[error("Invalid function selector")]
InvalidSelector,
#[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("Function selector is not found.")]
SelectorNotFound,
#[error("Stack index is out of range {0}, max is 255 (0x400)")]
StackIndexOutOfRange(u16),
#[error("Stack overflow, max is 1024 stack items, but add {1} to {0}")]
StackOverflow(u16, u16),
#[error("Stack underflow, current stack items {0}, expect at least {1}")]
StackUnderflow(u16, u16),
#[error("Stack not balanced, current stack items {0}")]
StackNotBalanced(u16),
#[error("Unsupported host function {0:?}")]
UnsupportedHostFunc(crate::wasm::HostFunc),
}
pub type Result<T> = std::result::Result<T, Error>;