tc_executor_common/
error.rs1use serializer;
22use twasmi;
23
24pub type Result<T> = std::result::Result<T, Error>;
26
27#[derive(Debug, thiserror::Error)]
29#[allow(missing_docs)]
30pub enum Error {
31 #[error("Unserializable data encountered")]
32 InvalidData(#[from] serializer::Error),
33
34 #[error(transparent)]
35 Trap(#[from] twasmi::Trap),
36
37 #[error(transparent)]
38 Wasmi(#[from] twasmi::Error),
39
40 #[error("API Error: {0}")]
41 ApiError(String),
42
43 #[error("Method not found: '{0}'")]
44 MethodNotFound(String),
45
46 #[error("Invalid Code (expected single byte): '{0}'")]
47 InvalidCode(String),
48
49 #[error("On-chain runtime does not specify version")]
50 VersionInvalid,
51
52 #[error("Externalities error")]
53 Externalities,
54
55 #[error("Invalid index provided")]
56 InvalidIndex,
57
58 #[error("Invalid type returned (should be u64)")]
59 InvalidReturn,
60
61 #[error("Runtime error")]
62 Runtime,
63
64 #[error("Runtime panicked: {0}")]
65 RuntimePanicked(String),
66
67 #[error("Invalid memory reference")]
68 InvalidMemoryReference,
69
70 #[error("The runtime doesn't provide a global named `__heap_base` of type `i32`")]
71 HeapBaseNotFoundOrInvalid,
72
73 #[error("The runtime must not have the `start` function defined")]
74 RuntimeHasStartFn,
75
76 #[error("Other: {0}")]
77 Other(String),
78
79 #[error(transparent)]
80 Allocator(#[from] tp_allocator::Error),
81
82 #[error("Host function {0} execution failed with: {1}")]
83 FunctionExecution(String, String),
84
85 #[error("No table exported by wasm blob")]
86 NoTable,
87
88 #[error("No table entry with index {0} in wasm blob exported table")]
89 NoTableEntryWithIndex(u32),
90
91 #[error("Table element with index {0} is not a function in wasm blob exported table")]
92 TableElementIsNotAFunction(u32),
93
94 #[error("Table entry with index {0} in wasm blob is null")]
95 FunctionRefIsNull(u32),
96
97 #[error(transparent)]
98 RuntimeConstruction(#[from] WasmError),
99
100 #[error("Shared memory is not supported")]
101 SharedMemUnsupported,
102
103 #[error("Imported globals are not supported yet")]
104 ImportedGlobalsUnsupported,
105
106 #[error("initializer expression can have only up to 2 expressions in wasm 1.0")]
107 InitializerHasTooManyExpressions,
108
109 #[error("Invalid initializer expression provided {0}")]
110 InvalidInitializerExpression(String),
111}
112
113impl twasmi::HostError for Error {}
114
115impl From<&'static str> for Error {
116 fn from(err: &'static str) -> Error {
117 Error::Other(err.into())
118 }
119}
120
121impl From<String> for Error {
122 fn from(err: String) -> Error {
123 Error::Other(err)
124 }
125}
126
127#[derive(Debug, derive_more::Display)]
129pub enum WasmError {
130 CodeNotFound,
132 ApplySnapshotFailed,
134 ErasingFailed(String),
138 InvalidModule,
140 CantDeserializeWasm,
142 InvalidMemory,
144 InvalidHeapPages,
146 Instantiation(String),
148 Other(String),
150}
151
152impl std::error::Error for WasmError {}