ceres_runtime/
result.rs

1//! Custom result
2use ceres_std::{String, Vec};
3
4/// Ceres Error
5#[derive(Debug)]
6pub enum Error {
7    /// Memory out of bounds
8    OutOfBounds,
9    /// Decoding data failed in sandbox
10    DecodeRuntimeValueFailed,
11    /// Output buffer too small
12    OutputBufferTooSmall,
13    ReturnData {
14        flags: u32,
15        data: Vec<u8>,
16    },
17    /// Failed to parse wasm module
18    ParseWasmModuleFailed,
19    /// Failed to parse name section
20    ParseNameSectionFailed {
21        error: String,
22    },
23    /// Failed to calcuate memory limit
24    CalcuateMemoryLimitFailed,
25    /// Failed to alloc memory
26    AllocMemoryFailed,
27    SerializeFailed {
28        error: parity_wasm::SerializationError,
29    },
30    /// Init ModuleInstance failed
31    InitModuleFailed {
32        error: ceres_executor::Error,
33    },
34    /// Deploy contract failed
35    DeployContractFailed {
36        error: ceres_executor::Error,
37    },
38    CallContractFailed {
39        error: ceres_executor::Error,
40    },
41    /// Decode selector failed
42    DecodeSelectorFailed,
43    /// Decode contract failed
44    DecodeContractFailed,
45    /// The length of arguments is not correct
46    InvalidArgumentLength {
47        expect: usize,
48        input: usize,
49    },
50    /// Decode argument failed
51    DecodeArgumentFailed {
52        arg: Vec<u8>,
53    },
54    GetMethodFailed {
55        name: String,
56    },
57    /// Could not set Storage
58    CouldNotSetStorage,
59    /// Get Storage failed
60    GetStorageFailed,
61    /// Invalid code hash
62    InvalidCodeHash,
63    Custom(&'static str),
64    /// Insert Contract failed
65    InsertContractFailed,
66    /// Get Contract failed
67    GetContractFailed,
68    /// SerdeError
69    SerdeError,
70    ExecutorNotInited,
71    InitExecutorFailed,
72    /// Executor Error
73    ExecuteWasmFailed(ceres_executor::Error),
74    LoadDataFailed,
75    FlushDataFailed,
76}
77
78impl From<ceres_executor::Error> for Error {
79    fn from(e: ceres_executor::Error) -> Error {
80        Error::ExecuteWasmFailed(e)
81    }
82}
83
84impl From<&'static str> for Error {
85    fn from(e: &'static str) -> Error {
86        Error::Custom(e)
87    }
88}
89
90impl PartialEq for Error {
91    fn eq(&self, other: &Self) -> bool {
92        match self {
93            Error::SerializeFailed { error: _ } => false,
94            _ => self.eq(other),
95        }
96    }
97}
98
99impl Eq for Error {}
100
101/// Wrapped result
102pub type Result<T> = core::result::Result<T, Error>;