truthlinked_axiom/
error.rs1#[derive(Debug, Clone, PartialEq, Eq)]
7pub enum AxiomError {
8 OutOfGas,
9 CallDepthExceeded,
10 InvalidOpcode(u8),
11 DivisionByZero,
12 ArithmeticOverflow,
13 InvalidJumpTarget(u32),
14 InvalidRegister(u8),
15 InvalidConstIndex(u16),
16 ReturnDataTooLarge,
17 InvalidLength(usize),
18 LogTooLarge,
19 StorageReadFailed,
20 StorageWriteFailed,
21 Unauthorized,
22 AssertFailed,
23 CrossCellFailed(alloc::string::String),
24 BufOverflow,
25 Trap(u16),
26 InvalidBytecode,
27 InvalidMagic,
28 NotImplemented(u8),
29}
30
31impl AxiomError {
32 pub fn code(&self) -> i32 {
33 match self {
34 Self::OutOfGas => -100_001,
35 Self::CallDepthExceeded => -100_002,
36 Self::InvalidOpcode(_) => -100_003,
37 Self::DivisionByZero => -100_004,
38 Self::ArithmeticOverflow => -100_005,
39 Self::InvalidJumpTarget(_) => -100_006,
40 Self::InvalidRegister(_) => -100_007,
41 Self::InvalidConstIndex(_) => -100_008,
42 Self::ReturnDataTooLarge => -100_009,
43 Self::InvalidLength(_) => -100_018,
44 Self::LogTooLarge => -100_010,
45 Self::StorageReadFailed => -100_011,
46 Self::StorageWriteFailed => -100_012,
47 Self::Unauthorized => -100_013,
48 Self::AssertFailed => -100_014,
49 Self::CrossCellFailed(_) => -100_015,
50 Self::BufOverflow => -100_020,
51 Self::Trap(c) => -(*c as i32),
52 Self::InvalidBytecode => -100_016,
53 Self::InvalidMagic => -100_017,
54 Self::NotImplemented(_) => -100_019,
55 }
56 }
57}
58
59impl core::fmt::Display for AxiomError {
60 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
61 write!(f, "{:?}", self)
62 }
63}