fce_wit_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 wasmer_wit::decoders::wat::Error as WATError;
18use thiserror::Error as ThisError;
19
20use std::io::Error as IOError;
21
22#[derive(Debug, ThisError)]
23pub enum WITParserError {
24 /// WIT section is absent.
25 #[error("the module doesn't contain IT section")]
26 NoITSection,
27
28 /// Multiple WIT sections.
29 #[error("the module contains multiple IT sections that is unsupported")]
30 MultipleITSections,
31
32 /// WIT section remainder isn't empty.
33 #[error("IT section is corrupted: IT section remainder isn't empty")]
34 ITRemainderNotEmpty,
35
36 /// An error occurred while parsing WIT section.
37 #[error(
38 "IT section is corrupted: {0}.\
39 \nProbably the module was compiled with an old version of fce cli, please try to update and recompile.\
40 \nTo update fce run: cargo install fcli --force"
41 )]
42 CorruptedITSection(nom::Err<(Vec<u8>, nom::error::ErrorKind)>),
43
44 /// An error related to incorrect data of wit section.
45 #[error("{0}")]
46 IncorrectITFormat(String),
47
48 /// An error occurred while parsing file in Wat format.
49 #[error("provided file with IT definitions is corrupted: {0}")]
50 CorruptedITFile(#[from] WATError),
51
52 /// An error occurred while parsing Wasm file.
53 #[error("provided Wasm file is corrupted: {0}")]
54 CorruptedWasmFile(anyhow::Error),
55
56 /// An error occurred while manipulating with converting ast to bytes.
57 #[error("Convertation Wast to AST failed with: {0}")]
58 AstToBytesError(#[from] IOError),
59
60 /// Wasm emitting file error.
61 #[error("Emitting resulted Wasm file failed with: {0}")]
62 WasmEmitError(anyhow::Error),
63}