1pub use gear_wasm_instrument::{InstrumentationError, ModuleError};
22pub use wasmparser::BinaryReaderError;
23
24#[derive(PartialEq, Eq, Debug, derive_more::Display)]
26pub enum SectionName {
27 #[display(fmt = "Type section")]
29 Type,
30 #[display(fmt = "Import section")]
32 Import,
33 #[display(fmt = "Function section")]
35 Function,
36 #[display(fmt = "Data section")]
38 Data,
39 #[display(fmt = "Global section")]
41 Global,
42 #[display(fmt = "Table section")]
44 Table,
45 #[display(fmt = "Element section")]
47 Element,
48 #[display(fmt = "Export section")]
50 Export,
51 #[display(fmt = "Start section")]
53 Start,
54}
55
56#[derive(Debug, derive_more::Display)]
58pub enum SectionError {
59 #[display(fmt = "{_0} not found")]
61 NotFound(SectionName),
62 #[display(fmt = "{_0} not supported")]
64 NotSupported(SectionName),
65}
66
67#[derive(Debug, derive_more::Display)]
69pub enum MemoryError {
70 #[display(fmt = "Memory entry not found")]
72 EntryNotFound,
73 #[display(fmt = "The WASM module has invalid count of static memory pages")]
75 InvalidStaticPageCount,
76}
77
78#[derive(Debug, derive_more::Display)]
80pub enum StackEndError {
81 #[display(fmt = "Unsupported initialization of gear stack end global")]
83 Initialization,
84 #[display(fmt = "Gear stack end {_0:#x} is not aligned to wasm page size")]
86 NotAligned(u32),
87 #[display(fmt = "Gear stack end {_0:#x} is out of static memory 0x0..{_1:#x}")]
89 OutOfStatic(u32, u64),
90}
91
92#[derive(Debug, derive_more::Display)]
94pub enum DataSectionError {
95 #[display(fmt = "Unsupported initialization of data segment")]
97 Initialization,
98 #[display(fmt = "Data segment {_0:#x} overlaps gear stack 0x0..{_1:#x}")]
100 GearStackOverlaps(u32, u32),
101 #[display(fmt = "Data segment {_0:#x} ends out of possible 32 bits address space")]
103 EndAddressOverflow(u32),
104 #[display(fmt = "Data segment {_0:#x}..={_1:#x} is out of static memory 0x0..{_2:#x}")]
106 EndAddressOutOfStaticMemory(u32, u32, u64),
107 #[display(fmt = "Data segment amount limit exceeded: limit={limit}, actual={actual}")]
109 DataSegmentsAmountLimit {
110 limit: u32,
112 actual: u32,
114 },
115}
116
117#[derive(Debug, derive_more::Display)]
119pub enum ExportError {
120 #[display(fmt = "Global index `{_0}` in export index `{_1}` is incorrect")]
122 IncorrectGlobalIndex(u32, u32),
123 #[display(fmt = "Global index `{_0}` in export index `{_1}` cannot be mutable")]
125 MutableGlobalExport(u32, u32),
126 #[display(fmt = "Export index `{_0}` references to imported function with index `{_1}`")]
128 ExportReferencesToImportFunction(u32, u32),
129 #[display(fmt = "Export index `{_0}` references to imported global with index `{_1}`")]
131 ExportReferencesToImportGlobal(u32, u32),
132 #[display(fmt = "Exported function with index `{_0}` must have signature `fn f() {{ ... }}`")]
134 InvalidExportFnSignature(u32),
135 #[display(fmt = "Excess export with index `{_0}` found")]
137 ExcessExport(u32),
138 #[display(fmt = "Required export function `init` or `handle` is not found")]
140 RequiredExportNotFound,
141}
142
143#[derive(Debug, derive_more::Display)]
145pub enum ImportError {
146 #[display(fmt = "Unknown imported function with index `{_0}`")]
148 UnknownImport(u32),
149 #[display(fmt = "Imported function with index `{_0}` is declared multiple times")]
151 DuplicateImport(u32),
152 #[display(fmt = "Invalid function signature for imported function with index `{_0}`")]
154 InvalidImportFnSignature(u32),
155 #[display(fmt = "Unexpected import kind `{kind}` with index `{index}`")]
157 UnexpectedImportKind {
158 kind: &'static &'static str,
160 index: u32,
162 },
163}
164
165#[derive(Debug, derive_more::Display, derive_more::From)]
167pub enum CodeError {
168 #[display(fmt = "wasmparser validation error: {_0}")]
170 Validation(BinaryReaderError),
171 #[display(fmt = "Codec error: {_0}")]
173 Module(ModuleError),
174 #[display(fmt = "Section error: {_0}")]
176 Section(SectionError),
177 #[display(fmt = "Memory error: {_0}")]
179 Memory(MemoryError),
180 #[display(fmt = "Stack end error: {_0}")]
182 StackEnd(StackEndError),
183 #[display(fmt = "Data section error: {_0}")]
185 DataSection(DataSectionError),
186 #[display(fmt = "Export error: {_0}")]
188 Export(ExportError),
189 #[display(fmt = "Import error: {_0}")]
191 Import(ImportError),
192 #[display(fmt = "Instrumentation error: {_0}")]
194 Instrumentation(InstrumentationError),
195}
196
197impl core::error::Error for CodeError {}