sc_executor_common/
error.rs1pub type Result<T> = std::result::Result<T, Error>;
23
24#[derive(Debug, thiserror::Error)]
26#[allow(missing_docs)]
27pub enum Error {
28 #[error("Error calling api function: {0}")]
29 ApiError(Box<dyn std::error::Error + Send + Sync>),
30
31 #[error("Method not found: '{0}'")]
32 MethodNotFound(String),
33
34 #[error("On-chain runtime does not specify version")]
35 VersionInvalid,
36
37 #[error("Externalities error")]
38 Externalities,
39
40 #[error("Invalid index provided")]
41 InvalidIndex,
42
43 #[error("Invalid type returned (should be u64)")]
44 InvalidReturn,
45
46 #[error("Runtime panicked: {0}")]
47 RuntimePanicked(String),
48
49 #[error("Invalid memory reference")]
50 InvalidMemoryReference,
51
52 #[error("The runtime doesn't provide a global named `__heap_base` of type `i32`")]
53 HeapBaseNotFoundOrInvalid,
54
55 #[error("The runtime must not have the `start` function defined")]
56 RuntimeHasStartFn,
57
58 #[error("Other: {0}")]
59 Other(String),
60
61 #[error(transparent)]
62 Allocator(#[from] sc_allocator::Error),
63
64 #[error("Host function {0} execution failed with: {1}")]
65 FunctionExecution(String, String),
66
67 #[error("No table exported by wasm blob")]
68 NoTable,
69
70 #[error("No table entry with index {0} in wasm blob exported table")]
71 NoTableEntryWithIndex(u32),
72
73 #[error("Table element with index {0} is not a function in wasm blob exported table")]
74 TableElementIsNotAFunction(u32),
75
76 #[error("Table entry with index {0} in wasm blob is null")]
77 FunctionRefIsNull(u32),
78
79 #[error(transparent)]
80 RuntimeConstruction(#[from] WasmError),
81
82 #[error("Shared memory is not supported")]
83 SharedMemUnsupported,
84
85 #[error("Imported globals are not supported yet")]
86 ImportedGlobalsUnsupported,
87
88 #[error("initializer expression can have only up to 2 expressions in wasm 1.0")]
89 InitializerHasTooManyExpressions,
90
91 #[error("Invalid initializer expression provided {0}")]
92 InvalidInitializerExpression(String),
93
94 #[error("Execution aborted due to panic: {0}")]
95 AbortedDueToPanic(MessageWithBacktrace),
96
97 #[error("Execution aborted due to trap: {0}")]
98 AbortedDueToTrap(MessageWithBacktrace),
99
100 #[error("Output exceeds bounds of wasm memory")]
101 OutputExceedsBounds,
102}
103
104impl From<&'static str> for Error {
105 fn from(err: &'static str) -> Error {
106 Error::Other(err.into())
107 }
108}
109
110impl From<String> for Error {
111 fn from(err: String) -> Error {
112 Error::Other(err)
113 }
114}
115
116#[derive(Debug, thiserror::Error)]
118#[allow(missing_docs)]
119pub enum WasmError {
120 #[error("Code could not be read from the state.")]
121 CodeNotFound,
122
123 #[error("Failure to reinitialize runtime instance from snapshot.")]
124 ApplySnapshotFailed,
125
126 #[error("Failure to erase the wasm memory: {0}")]
130 ErasingFailed(String),
131
132 #[error("Wasm code failed validation.")]
133 InvalidModule,
134
135 #[error("Wasm code could not be deserialized.")]
136 CantDeserializeWasm,
137
138 #[error("The module does not export a linear memory named `memory`.")]
139 InvalidMemory,
140
141 #[error("The number of heap pages requested is disallowed by the module.")]
142 InvalidHeapPages,
143
144 #[error("{0}")]
146 Instantiation(String),
147
148 #[error("Other error happened while constructing the runtime: {0}")]
150 Other(String),
151}
152
153impl From<polkavm::program::ProgramParseError> for WasmError {
154 fn from(error: polkavm::program::ProgramParseError) -> Self {
155 WasmError::Other(error.to_string())
156 }
157}
158
159impl From<polkavm::Error> for WasmError {
160 fn from(error: polkavm::Error) -> Self {
161 WasmError::Other(error.to_string())
162 }
163}
164
165impl From<polkavm::Error> for Error {
166 fn from(error: polkavm::Error) -> Self {
167 Error::Other(error.to_string())
168 }
169}
170
171#[derive(Debug)]
173pub struct MessageWithBacktrace {
174 pub message: String,
176
177 pub backtrace: Option<Backtrace>,
179}
180
181impl std::fmt::Display for MessageWithBacktrace {
182 fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
183 fmt.write_str(&self.message)?;
184 if let Some(ref backtrace) = self.backtrace {
185 fmt.write_str("\nWASM backtrace:\n")?;
186 backtrace.backtrace_string.fmt(fmt)?;
187 }
188
189 Ok(())
190 }
191}
192
193#[derive(Debug)]
195pub struct Backtrace {
196 pub backtrace_string: String,
198}
199
200impl std::fmt::Display for Backtrace {
201 fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
202 fmt.write_str(&self.backtrace_string)
203 }
204}