2020-04-18 18:27:01 +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.
|
|
|
|
*/
|
|
|
|
|
2021-03-16 13:51:59 +03:00
|
|
|
use crate::HostImportError;
|
2021-12-03 20:33:46 +03:00
|
|
|
use crate::misc::PrepareError;
|
|
|
|
|
2021-05-10 12:51:22 +03:00
|
|
|
use marine_it_interfaces::MITInterfacesError;
|
|
|
|
use marine_it_parser::ITParserError;
|
2021-05-20 20:20:57 +03:00
|
|
|
use marine_module_interface::it_interface::ITInterfaceError;
|
2022-03-16 04:05:15 +04:00
|
|
|
use marine_wasm_backend_traits::{CallError, ResolveError, RuntimeError, WasmBackendError};
|
|
|
|
//use wasmer_runtime::error as wasmer_error;
|
2020-04-18 18:27:01 +03:00
|
|
|
|
2021-04-12 00:21:47 +03:00
|
|
|
use thiserror::Error as ThisError;
|
2022-03-16 04:05:15 +04:00
|
|
|
//use wasmer_core::error::ResolveError;
|
2020-04-22 16:25:24 +03:00
|
|
|
|
2021-03-16 13:51:59 +03:00
|
|
|
// TODO: refactor errors
|
2021-12-03 20:33:46 +03:00
|
|
|
// TODO: add module name to all errors variants
|
2021-03-16 13:51:59 +03:00
|
|
|
|
2021-04-12 00:21:47 +03:00
|
|
|
#[derive(Debug, ThisError)]
|
2021-05-10 12:51:22 +03:00
|
|
|
pub enum MError {
|
2020-04-18 18:27:01 +03:00
|
|
|
/// This error type is produced by Wasmer during resolving a Wasm function.
|
2021-09-28 16:30:40 +03:00
|
|
|
#[error("Wasmer resolve error: {0}")]
|
2022-03-16 04:05:15 +04:00
|
|
|
ResolveError(#[from] ResolveError),
|
2020-04-18 18:27:01 +03:00
|
|
|
|
|
|
|
/// Error related to calling a main Wasm module.
|
2021-09-28 16:30:40 +03:00
|
|
|
#[error("Wasmer invoke error: {0}")]
|
2020-04-18 18:27:01 +03:00
|
|
|
WasmerInvokeError(String),
|
2022-03-18 02:43:04 +04:00
|
|
|
/*
|
|
|
|
/// Error that raises during compilation Wasm code by Wasmer.
|
|
|
|
#[error("Wasmer creation error: {0}")]
|
|
|
|
WasmerCreationError(#[from] wasmer_error::CreationError),
|
2020-04-18 18:27:01 +03:00
|
|
|
|
2022-03-18 02:43:04 +04:00
|
|
|
/// Error that raises during creation of some Wasm objects (like table and memory) by Wasmer.
|
|
|
|
#[error("Wasmer compile error: {0}")]
|
|
|
|
WasmerCompileError(#[from] wasmer_error::CompileError),
|
|
|
|
*/
|
2021-04-12 00:21:47 +03:00
|
|
|
/// Errors arisen during execution of a Wasm module.
|
2021-09-28 16:30:40 +03:00
|
|
|
#[error("Wasmer runtime error: {0}")]
|
2021-04-12 00:21:47 +03:00
|
|
|
WasmerRuntimeError(String),
|
|
|
|
|
2022-03-16 04:05:15 +04:00
|
|
|
/*
|
2022-03-18 02:43:04 +04:00
|
|
|
/// Errors arisen during linking Wasm modules with already loaded into Marine modules.
|
|
|
|
#[error("Wasmer link error: {0}")]
|
|
|
|
WasmerLinkError(#[from] wasmer_error::LinkError),
|
|
|
|
*/
|
2021-04-12 00:21:47 +03:00
|
|
|
/// Errors from the temporary class of amalgamation errors from the Wasmer side.
|
2021-09-28 16:30:40 +03:00
|
|
|
#[error("Wasmer error: {0}")]
|
2021-04-12 00:21:47 +03:00
|
|
|
WasmerError(String),
|
|
|
|
|
|
|
|
/// Errors related to failed resolving of records.
|
|
|
|
#[error("{0}")]
|
|
|
|
RecordResolveError(String),
|
|
|
|
|
|
|
|
/// Errors arisen during creation of a WASI context.
|
|
|
|
#[error("{0}")]
|
|
|
|
WASIPrepareError(String),
|
|
|
|
|
2021-05-20 20:20:57 +03:00
|
|
|
/// Errors occurred inside marine-module-interface crate.
|
2021-09-28 16:30:40 +03:00
|
|
|
#[error(transparent)]
|
2021-05-20 20:20:57 +03:00
|
|
|
ModuleInterfaceError(#[from] ITInterfaceError),
|
|
|
|
|
2021-04-12 00:21:47 +03:00
|
|
|
/// Error arisen during execution of Wasm modules (especially, interface types).
|
|
|
|
#[error("Execution error: {0}")]
|
2021-05-10 12:51:22 +03:00
|
|
|
ITInstructionError(#[from] wasmer_it::errors::InstructionError),
|
2020-04-18 18:27:01 +03:00
|
|
|
|
2020-04-22 16:11:57 +03:00
|
|
|
/// Error that raises on the preparation step.
|
2021-12-03 20:33:46 +03:00
|
|
|
#[error(transparent)]
|
|
|
|
PrepareError(#[from] PrepareError),
|
2020-04-28 05:00:20 +03:00
|
|
|
|
|
|
|
/// Indicates that there is already a module with such name.
|
2021-09-28 16:30:40 +03:00
|
|
|
#[error("module with name '{0}' already loaded into Marine, please specify another name")]
|
2020-10-21 22:21:16 +03:00
|
|
|
NonUniqueModuleName(String),
|
2020-04-28 05:00:20 +03:00
|
|
|
|
2020-06-03 23:19:07 +03:00
|
|
|
/// Returns when there is no module with such name.
|
2021-09-28 16:30:40 +03:00
|
|
|
#[error("module with name '{0}' doesn't have function with name {1}")]
|
2021-04-12 00:21:47 +03:00
|
|
|
NoSuchFunction(String, String),
|
2020-06-03 23:19:07 +03:00
|
|
|
|
|
|
|
/// Returns when there is no module with such name.
|
2021-09-28 16:30:40 +03:00
|
|
|
#[error("module with name '{0}' isn't loaded into Marine")]
|
2020-07-11 23:04:55 +03:00
|
|
|
NoSuchModule(String),
|
2020-05-09 00:39:42 +03:00
|
|
|
|
2020-10-01 12:19:38 +03:00
|
|
|
/// An error occurred when host functions tries to lift IValues from WValues and lowering back.
|
2021-09-28 16:30:40 +03:00
|
|
|
#[error(transparent)]
|
2021-04-12 00:21:47 +03:00
|
|
|
HostImportError(#[from] HostImportError),
|
2020-10-01 12:19:38 +03:00
|
|
|
|
2021-05-10 12:51:22 +03:00
|
|
|
/// IT section parse error.
|
2021-09-28 16:30:40 +03:00
|
|
|
#[error(transparent)]
|
2021-05-10 12:51:22 +03:00
|
|
|
WITParseError(#[from] ITParserError),
|
2020-06-03 23:19:07 +03:00
|
|
|
|
2021-05-10 12:51:22 +03:00
|
|
|
/// Incorrect IT section.
|
2021-04-12 00:21:47 +03:00
|
|
|
#[error("{0}")]
|
2020-06-04 19:06:23 +03:00
|
|
|
IncorrectWIT(String),
|
2022-02-25 22:28:28 +03:00
|
|
|
|
|
|
|
#[error("WASM BACKEND ERROR: {0}")]
|
2022-02-26 17:19:34 +03:00
|
|
|
WasmBackendError(WasmBackendError),
|
2020-04-18 18:27:01 +03:00
|
|
|
}
|
|
|
|
|
2021-05-10 12:51:22 +03:00
|
|
|
impl From<MITInterfacesError> for MError {
|
|
|
|
fn from(err: MITInterfacesError) -> Self {
|
|
|
|
MError::IncorrectWIT(format!("{}", err))
|
2020-04-18 18:27:01 +03:00
|
|
|
}
|
|
|
|
}
|
2020-06-04 19:06:23 +03:00
|
|
|
|
2022-03-16 04:05:15 +04:00
|
|
|
impl From<RuntimeError> for MError {
|
|
|
|
fn from(err: RuntimeError) -> Self {
|
2021-04-12 00:21:47 +03:00
|
|
|
Self::WasmerRuntimeError(err.to_string())
|
2020-06-04 19:06:23 +03:00
|
|
|
}
|
|
|
|
}
|
2020-06-04 19:54:23 +03:00
|
|
|
|
2022-03-16 04:05:15 +04:00
|
|
|
impl From<CallError> for MError {
|
|
|
|
fn from(err: CallError) -> Self {
|
|
|
|
Self::WasmerInvokeError(err.to_string())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
2021-05-10 12:51:22 +03:00
|
|
|
impl From<wasmer_error::Error> for MError {
|
2021-04-12 00:21:47 +03:00
|
|
|
fn from(err: wasmer_error::Error) -> Self {
|
|
|
|
Self::WasmerError(err.to_string())
|
2020-06-04 19:54:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-10 12:51:22 +03:00
|
|
|
impl From<wasmer_error::InvokeError> for MError {
|
2021-04-12 00:21:47 +03:00
|
|
|
fn from(err: wasmer_error::InvokeError) -> Self {
|
|
|
|
Self::WasmerInvokeError(err.to_string())
|
2021-03-16 13:51:59 +03:00
|
|
|
}
|
|
|
|
}
|
2022-03-16 04:05:15 +04:00
|
|
|
*/
|
2021-05-10 12:51:22 +03:00
|
|
|
impl From<()> for MError {
|
2020-06-04 19:54:23 +03:00
|
|
|
fn from(_err: ()) -> Self {
|
2021-05-10 12:51:22 +03:00
|
|
|
MError::IncorrectWIT("failed to parse instructions for adapter type".to_string())
|
2020-06-04 19:54:23 +03:00
|
|
|
}
|
|
|
|
}
|
2022-02-25 22:28:28 +03:00
|
|
|
|
|
|
|
impl From<WasmBackendError> for MError {
|
|
|
|
fn from(err: WasmBackendError) -> Self {
|
|
|
|
MError::WasmBackendError(err)
|
|
|
|
}
|
|
|
|
}
|