Skip to main content

sbpf_runtime/
errors.rs

1use {sbpf_vm::errors::SbpfVmError, thiserror::Error};
2
3#[derive(Error, Debug)]
4pub enum RuntimeError {
5    #[error("Failed to read ELF file: {0}")]
6    ElfReadError(#[from] std::io::Error),
7
8    #[error("Failed to parse ELF: {0}")]
9    ElfParseError(String),
10
11    #[error("VM error: {0}")]
12    VmError(#[from] SbpfVmError),
13
14    #[error("Missing account: {0}")]
15    MissingAccount(String),
16
17    #[error("Program not found: {0}")]
18    ProgramNotFound(String),
19
20    #[error("CPI depth exceeded (max: {0})")]
21    CpiDepthExceeded(usize),
22
23    #[error("CPI privilege escalation: {0} on account {1}")]
24    PrivilegeEscalation(String, String),
25
26    #[error("VM not prepared — call prepare() or run() first")]
27    VmNotPrepared,
28
29    #[error("Register index {0} out of range")]
30    RegisterOutOfRange(usize),
31
32    #[error("Builtin program error: {0}")]
33    BuiltinError(String),
34
35    #[error("External account lamport spend: {0}")]
36    ExternalAccountLamportSpend(String),
37
38    #[error("Unbalanced lamports: pre={0}, post={1}")]
39    UnbalancedInstruction(u64, u64),
40}
41
42pub type RuntimeResult<T> = Result<T, RuntimeError>;