marine_it_parser/
errors.rs

1/*
2 * Copyright 2020 Fluence Labs Limited
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17use marine_module_interface::interface::InterfaceError;
18use marine_module_interface::it_interface::ITInterfaceError;
19
20use wasmer_it::decoders::wat::Error as WATError;
21use thiserror::Error as ThisError;
22
23use std::io::Error as IOError;
24
25#[derive(Debug, ThisError)]
26pub enum ITParserError {
27    /// IT section is absent.
28    #[error("the module doesn't contain IT section")]
29    NoITSection,
30
31    /// Multiple IT sections.
32    #[error("the module contains multiple IT sections that is unsupported")]
33    MultipleITSections,
34
35    /// IT section remainder isn't empty.
36    #[error("IT section is corrupted: IT section remainder isn't empty")]
37    ITRemainderNotEmpty,
38
39    /// An error occurred while parsing IT section.
40    #[error(
41        "IT section is corrupted: {0}.\
42    \nProbably the module was compiled with an old version of marine cli, please try to update and recompile.\
43    \nTo update marine run: cargo install marine --force"
44    )]
45    CorruptedITSection(nom::Err<(Vec<u8>, nom::error::ErrorKind)>),
46
47    /// An error related to incorrect data in IT section.
48    #[error("0")]
49    IncorrectITFormat(String), // TODO: use a proper error type
50
51    /// An error occurred while processing module interface.
52    #[error(transparent)]
53    ModuleInterfaceError(#[from] InterfaceError),
54
55    /// An error occurred while processing module IT interface.
56    #[error(transparent)]
57    ModuleITInterfaceError(#[from] ITInterfaceError),
58
59    /// An error occurred while parsing file in Wat format.
60    #[error("provided file with IT definitions is corrupted: {0}")]
61    CorruptedITFile(#[from] WATError),
62
63    /// An error occurred while parsing Wasm file.
64    #[error("provided Wasm file is corrupted: {0}")]
65    CorruptedWasmFile(anyhow::Error),
66
67    /// An error occurred while manipulating with converting ast to bytes.
68    #[error("Convertation Wast to AST failed with: {0}")]
69    AstToBytesError(#[from] IOError),
70
71    /// Wasm emitting file error.
72    #[error("Emitting resulted Wasm file failed with: {0}")]
73    WasmEmitError(anyhow::Error),
74}