1
0
mirror of https://github.com/fluencelabs/marine.git synced 2025-04-18 21:32:12 +00:00

72 lines
2.2 KiB
Rust
Raw Normal View History

2020-06-04 12:46:12 +03:00
/*
* Copyright 2020 Fluence Labs Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use wasmer_wit::decoders::wat::Error as WATError;
2021-03-12 20:04:47 +03:00
use thiserror::Error as ThisError;
2020-06-04 12:46:12 +03:00
2021-03-12 20:04:47 +03:00
use std::io::Error as IOError;
#[derive(Debug, ThisError)]
2020-06-04 12:46:12 +03:00
pub enum WITParserError {
/// WIT section is absent.
2021-03-12 20:04:47 +03:00
#[error("the module doesn't contain IT section")]
NoITSection,
2020-06-04 12:46:12 +03:00
/// Multiple WIT sections.
2021-03-12 20:04:47 +03:00
#[error("the module contains multiple IT sections that is unsupported")]
MultipleITSections,
2020-06-04 12:46:12 +03:00
/// WIT section remainder isn't empty.
2021-03-12 20:04:47 +03:00
#[error("IT section is corrupted: IT section remainder isn't empty")]
ITRemainderNotEmpty,
2020-06-04 12:46:12 +03:00
/// An error occurred while parsing WIT section.
2021-03-12 20:04:47 +03:00
#[error("IT section is corrupted")]
CorruptedITSection,
2020-06-04 12:46:12 +03:00
2021-03-12 20:04:47 +03:00
/// An error related to incorrect data of wit section.
#[error("{0}")]
IncorrectITFormat(String),
2020-06-04 12:46:12 +03:00
/// An error occurred while parsing file in Wat format.
2021-03-12 20:04:47 +03:00
#[error("provided file with IT definitions is corrupted: {0}")]
CorruptedITFile(WATError),
2020-06-04 12:46:12 +03:00
2021-03-12 20:04:47 +03:00
/// An error occurred while parsing Wasm file.
#[error("provided Wasm file is corrupted: {0}")]
2020-06-04 12:46:12 +03:00
CorruptedWasmFile(anyhow::Error),
/// An error occurred while manipulating with converting ast to bytes.
2021-03-12 20:04:47 +03:00
#[error("Convertation Wast to AST failed with: {0}")]
AstToBytesError(IOError),
2020-06-04 12:46:12 +03:00
2021-03-12 20:04:47 +03:00
/// Wasm emitting file error.
#[error("Emitting resulted Wasm file failed with: {0}")]
2020-06-04 12:46:12 +03:00
WasmEmitError(anyhow::Error),
}
impl From<WATError> for WITParserError {
fn from(err: WATError) -> Self {
2021-03-12 20:04:47 +03:00
WITParserError::CorruptedITFile(err)
2020-06-04 12:46:12 +03:00
}
}
2021-03-12 20:04:47 +03:00
impl From<IOError> for WITParserError {
fn from(err: IOError) -> Self {
2020-06-04 12:46:12 +03:00
WITParserError::AstToBytesError(err)
}
}