owasm_vm/
error.rs

1use std::fmt::{self, Display};
2
3#[repr(i32)]
4#[derive(Debug, PartialEq, Clone, Copy)]
5// An enum representing all kinds of errors we have in the system, with 0 for no error.
6pub enum Error {
7    NoError = 0,
8    SpanTooSmallError = 1, // Span to write is too small.
9    // Rust-generated errors during compilation.
10    ValidationError = 2,           // Wasm code does not pass basic validation.
11    DeserializationError = 3,      // Fail to deserialize Wasm into Partity-wasm module.
12    SerializationError = 4,        // Fail to serialize Parity-wasm module into Wasm.
13    InvalidImportsError = 5,       // Wasm code contains invalid import symbols.
14    InvalidExportsError = 6,       // Wasm code contains invalid export symbols.
15    BadMemorySectionError = 7,     // Wasm code contains bad memory sections.
16    GasCounterInjectionError = 8,  // Fail to inject gas counter into Wasm code.
17    StackHeightInjectionError = 9, // Fail to inject stack height limit into Wasm code.
18    // Rust-generated errors during runtime.
19    InstantiationError = 10, // Error while instantiating Wasm with resolvers.
20    RuntimeError = 11,       // Runtime error while executing the Wasm script.
21    OutOfGasError = 12,      // Out-of-gas while executing the Wasm script.
22    BadEntrySignatureError = 13, // Bad execution entry point signature.
23    MemoryOutOfBoundError = 14, // Out-of-bound memory access while executing the wasm script
24    UninitializedContextData = 15, // Error while getting uninitialized context data.
25    ChecksumLengthNotMatch = 16, // Checksum not of intended length.
26    DataLengthOutOfBound = 17, // Data length is out of bound.
27    ConvertTypeOutOfBound = 18, // Error while try to convert type.
28    // Host-generated errors while interacting with OEI.
29    WrongPeriodActionError = 128, // OEI action to invoke is not available.
30    TooManyExternalDataError = 129, // Too many external data requests.
31    DuplicateExternalIDError = 130, // Wasm code asks data with duplicate external id.
32    BadValidatorIndexError = 131, // Bad validator index parameter.
33    BadExternalIDError = 132,     // Bad external ID parameter.
34    UnavailableExternalDataError = 133, // External data is not available.
35    RepeatSetReturnDataError = 134, // Set return data is called more than once.
36    // Unexpected error
37    UnknownError = 255,
38}
39
40impl std::error::Error for Error {}
41impl Display for Error {
42    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
43        write!(f, "{:?}", self)
44    }
45}
46
47#[cfg(test)]
48mod tests {
49    use super::*;
50
51    #[test]
52    fn fmt_works() {
53        assert_eq!(format!("{}", Error::NoError), "NoError");
54        assert_eq!(format!("{}", Error::SpanTooSmallError), "SpanTooSmallError");
55    }
56}