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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
use wasmer_runtime::error::{
|
2020-04-22 16:25:24 +03:00
|
|
|
CallError,
|
|
|
|
CompileError,
|
|
|
|
CreationError,
|
|
|
|
Error as WasmerError,
|
|
|
|
ResolveError,
|
|
|
|
RuntimeError,
|
2020-04-18 18:27:01 +03:00
|
|
|
};
|
|
|
|
|
2020-04-22 16:25:24 +03:00
|
|
|
use std::error::Error;
|
|
|
|
|
2020-04-18 18:27:01 +03:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum FrankError {
|
|
|
|
/// Errors related to the preparation (instrumentation and so on) and compilation by Wasmer steps.
|
|
|
|
InstantiationError(String),
|
|
|
|
|
|
|
|
/// Errors for I/O errors raising while opening a file.
|
|
|
|
IOError(String),
|
|
|
|
|
|
|
|
/// This error type is produced by Wasmer during resolving a Wasm function.
|
|
|
|
WasmerResolveError(String),
|
|
|
|
|
|
|
|
/// Error related to calling a main Wasm module.
|
|
|
|
WasmerInvokeError(String),
|
|
|
|
|
2020-04-22 16:11:57 +03:00
|
|
|
/// Error that raises during compilation Wasm code by Wasmer.
|
|
|
|
WasmerCreationError(String),
|
2020-04-18 18:27:01 +03:00
|
|
|
|
2020-04-22 16:11:57 +03:00
|
|
|
/// Error that raises during creation of some Wasm objects (like table and memory) by Wasmer.
|
|
|
|
WasmerCompileError(String),
|
2020-04-18 18:27:01 +03:00
|
|
|
|
2020-04-22 16:11:57 +03:00
|
|
|
/// Error that raises on the preparation step.
|
|
|
|
PrepareError(String),
|
2020-04-18 18:27:01 +03:00
|
|
|
}
|
|
|
|
|
2020-04-22 16:11:57 +03:00
|
|
|
impl Error for FrankError {}
|
|
|
|
|
2020-04-18 18:27:01 +03:00
|
|
|
impl std::fmt::Display for FrankError {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
|
|
|
|
match self {
|
|
|
|
FrankError::InstantiationError(msg) => write!(f, "InstantiationError: {}", msg),
|
|
|
|
FrankError::IOError(msg) => write!(f, "IOError: {}", msg),
|
|
|
|
FrankError::WasmerResolveError(msg) => write!(f, "WasmerResolveError: {}", msg),
|
|
|
|
FrankError::WasmerInvokeError(msg) => write!(f, "WasmerInvokeError: {}", msg),
|
2020-04-22 16:11:57 +03:00
|
|
|
FrankError::WasmerCompileError(msg) => write!(f, "WasmerCompileError: {}", msg),
|
|
|
|
FrankError::WasmerCreationError(msg) => write!(f, "WasmerCreationError: {}", msg),
|
|
|
|
FrankError::PrepareError(msg) => {
|
|
|
|
write!(f, "Prepare error: {}, probably module is mailformed", msg)
|
|
|
|
}
|
2020-04-18 18:27:01 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-22 16:11:57 +03:00
|
|
|
impl From<CreationError> for FrankError {
|
2020-04-18 18:27:01 +03:00
|
|
|
fn from(err: CreationError) -> Self {
|
2020-04-22 16:11:57 +03:00
|
|
|
FrankError::WasmerCreationError(format!("{}", err))
|
2020-04-18 18:27:01 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-22 16:11:57 +03:00
|
|
|
impl From<CompileError> for FrankError {
|
2020-04-18 18:27:01 +03:00
|
|
|
fn from(err: CompileError) -> Self {
|
2020-04-22 16:11:57 +03:00
|
|
|
FrankError::WasmerCompileError(format!("{}", err))
|
2020-04-18 18:27:01 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-22 16:11:57 +03:00
|
|
|
impl From<parity_wasm::elements::Error> for FrankError {
|
2020-04-18 18:27:01 +03:00
|
|
|
fn from(err: parity_wasm::elements::Error) -> Self {
|
2020-04-22 16:11:57 +03:00
|
|
|
FrankError::PrepareError(format!("{}", err))
|
2020-04-18 18:27:01 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<CallError> for FrankError {
|
|
|
|
fn from(err: CallError) -> Self {
|
|
|
|
match err {
|
|
|
|
CallError::Resolve(err) => FrankError::WasmerResolveError(format!("{}", err)),
|
|
|
|
CallError::Runtime(err) => FrankError::WasmerInvokeError(format!("{}", err)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<ResolveError> for FrankError {
|
|
|
|
fn from(err: ResolveError) -> Self {
|
|
|
|
FrankError::WasmerResolveError(format!("{}", err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<RuntimeError> for FrankError {
|
|
|
|
fn from(err: RuntimeError) -> Self {
|
|
|
|
FrankError::WasmerInvokeError(format!("{}", err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<WasmerError> for FrankError {
|
|
|
|
fn from(err: WasmerError) -> Self {
|
|
|
|
FrankError::WasmerInvokeError(format!("{}", err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<std::io::Error> for FrankError {
|
|
|
|
fn from(err: std::io::Error) -> Self {
|
|
|
|
FrankError::IOError(format!("{}", err))
|
|
|
|
}
|
|
|
|
}
|