2019-11-10 13:13:18 -06:00
//! The error module contains the data structures and helper functions used to implement errors that
//! are produced and returned from the wasmer runtime core.
2019-04-22 11:42:52 -07:00
use crate ::types ::{ FuncSig , GlobalDescriptor , MemoryDescriptor , TableDescriptor , Type } ;
2019-02-14 18:19:18 -08:00
use core ::borrow ::Borrow ;
2019-03-12 09:51:54 +01:00
use std ::any ::Any ;
2019-01-18 10:54:16 -08:00
2019-11-10 13:13:18 -06:00
/// Aliases the standard `Result` type as `Result` within this module.
2019-02-02 15:28:50 -08:00
pub type Result < T > = std ::result ::Result < T , Error > ;
2019-11-10 14:37:36 -06:00
/// Result of an attempt to compile the provided WebAssembly module into a `Module`.
2019-11-10 13:13:18 -06:00
/// Aliases the standard `Result` with `CompileError` as the default error type.
2019-02-02 15:28:50 -08:00
pub type CompileResult < T > = std ::result ::Result < T , CompileError > ;
2019-11-10 14:37:36 -06:00
/// Result of an attempt to link the provided WebAssembly instance.
2019-11-10 13:13:18 -06:00
/// Aliases the standard `Result` with `Vec<LinkError>` as the default error type.
2019-01-18 13:44:44 -08:00
pub type LinkResult < T > = std ::result ::Result < T , Vec < LinkError > > ;
2019-11-10 14:37:36 -06:00
/// Result of an attempt to run the provided WebAssembly instance.
2019-11-10 13:13:18 -06:00
/// Aliases the standard `Result` with `RuntimeError` as the default error type.
2019-02-02 15:28:50 -08:00
pub type RuntimeResult < T > = std ::result ::Result < T , RuntimeError > ;
2019-11-10 14:37:36 -06:00
/// Result of an attempt to call the provided WebAssembly instance.
2019-11-10 13:13:18 -06:00
/// Aliases the standard `Result` with `CallError` as the default error type.
2019-02-02 15:28:50 -08:00
pub type CallResult < T > = std ::result ::Result < T , CallError > ;
2019-11-10 14:37:36 -06:00
/// Result of an attempt to resolve a WebAssembly function by name.
2019-11-10 13:13:18 -06:00
/// Aliases the standard `Result` with `ResolveError` as the default error type.
2019-02-02 15:28:50 -08:00
pub type ResolveResult < T > = std ::result ::Result < T , ResolveError > ;
2019-11-10 14:37:36 -06:00
/// Result of an attempt to parse bytes into a WebAssembly module.
2019-11-10 13:13:18 -06:00
/// Aliases the standard `Result` with `ParseError` as the default error type.
2019-03-12 10:45:44 -07:00
pub type ParseResult < T > = std ::result ::Result < T , ParseError > ;
2019-01-18 10:54:16 -08:00
/// This is returned when the chosen compiler is unable to
2019-05-13 11:18:57 -07:00
/// successfully compile the provided WebAssembly module into
2019-01-18 10:54:16 -08:00
/// a `Module`.
///
/// Comparing two `CompileError`s always evaluates to false.
#[ derive(Debug, Clone) ]
pub enum CompileError {
2019-11-10 13:13:18 -06:00
/// A validation error containing an error message.
ValidationError {
/// An error message.
msg : String ,
} ,
/// A internal error containing an error message.
InternalError {
/// An error message.
msg : String ,
} ,
2019-01-18 10:54:16 -08:00
}
impl PartialEq for CompileError {
fn eq ( & self , _other : & CompileError ) -> bool {
false
}
}
2019-02-14 21:08:35 -08:00
impl std ::fmt ::Display for CompileError {
fn fmt ( & self , f : & mut std ::fmt ::Formatter ) -> std ::fmt ::Result {
match self {
CompileError ::InternalError { msg } = > {
write! ( f , " Internal compiler error: \" {} \" " , msg )
}
CompileError ::ValidationError { msg } = > write! ( f , " Validation error \" {} \" " , msg ) ,
}
}
}
impl std ::error ::Error for CompileError { }
2019-01-18 10:54:16 -08:00
/// This is returned when the runtime is unable to
/// correctly link the module with the provided imports.
///
/// Comparing two `LinkError`s always evaluates to false.
#[ derive(Debug, Clone) ]
pub enum LinkError {
2019-11-10 13:13:18 -06:00
/// The type of the provided import does not match the expected type.
2019-01-18 10:54:16 -08:00
IncorrectImportType {
2019-11-10 13:13:18 -06:00
/// Namespace.
2019-01-18 10:54:16 -08:00
namespace : String ,
2019-11-10 13:13:18 -06:00
/// Name.
2019-01-18 10:54:16 -08:00
name : String ,
2019-11-10 13:13:18 -06:00
/// Expected.
2019-01-18 10:54:16 -08:00
expected : String ,
2019-11-10 13:13:18 -06:00
/// Found.
2019-01-18 10:54:16 -08:00
found : String ,
} ,
2019-11-10 13:13:18 -06:00
/// The signature of the provided import does not match the expected signature.
2019-01-18 10:54:16 -08:00
IncorrectImportSignature {
2019-11-10 13:13:18 -06:00
/// Namespace.
2019-01-18 10:54:16 -08:00
namespace : String ,
2019-11-10 13:13:18 -06:00
/// Name.
2019-01-18 10:54:16 -08:00
name : String ,
2019-11-10 13:13:18 -06:00
/// Expected.
2019-02-08 14:19:58 -08:00
expected : FuncSig ,
2019-11-10 13:13:18 -06:00
/// Found.
2019-02-08 14:19:58 -08:00
found : FuncSig ,
2019-01-18 10:54:16 -08:00
} ,
2019-11-10 13:13:18 -06:00
/// An expected import was not provided.
2019-01-18 10:54:16 -08:00
ImportNotFound {
2019-11-10 13:13:18 -06:00
/// Namespace.
2019-01-18 10:54:16 -08:00
namespace : String ,
2019-11-10 13:13:18 -06:00
/// Name.
2019-01-18 10:54:16 -08:00
name : String ,
} ,
2019-11-10 13:13:18 -06:00
/// The memory descriptor provided does not match the expected descriptor.
2019-01-29 13:04:42 -08:00
IncorrectMemoryDescriptor {
2019-11-10 13:13:18 -06:00
/// Namespace.
2019-01-18 10:54:16 -08:00
namespace : String ,
2019-11-10 13:13:18 -06:00
/// Name.
2019-01-18 10:54:16 -08:00
name : String ,
2019-11-10 13:13:18 -06:00
/// Expected.
2019-01-29 13:04:42 -08:00
expected : MemoryDescriptor ,
2019-11-10 13:13:18 -06:00
/// Found.
2019-01-29 13:04:42 -08:00
found : MemoryDescriptor ,
2019-01-18 10:54:16 -08:00
} ,
2019-11-10 13:13:18 -06:00
/// The table descriptor provided does not match the expected descriptor.
2019-01-29 13:04:42 -08:00
IncorrectTableDescriptor {
2019-11-10 13:13:18 -06:00
/// Namespace.
2019-01-18 10:54:16 -08:00
namespace : String ,
2019-11-10 13:13:18 -06:00
/// Name.
2019-01-18 10:54:16 -08:00
name : String ,
2019-11-10 13:13:18 -06:00
/// Expected.
2019-01-29 13:04:42 -08:00
expected : TableDescriptor ,
2019-11-10 13:13:18 -06:00
/// Found.
2019-01-29 13:04:42 -08:00
found : TableDescriptor ,
2019-01-18 10:54:16 -08:00
} ,
2019-11-10 13:13:18 -06:00
/// The global descriptor provided does not match the expected descriptor.
2019-01-29 13:04:42 -08:00
IncorrectGlobalDescriptor {
2019-11-10 13:13:18 -06:00
/// Namespace.
2019-01-18 10:54:16 -08:00
namespace : String ,
2019-11-10 13:13:18 -06:00
/// Name.
2019-01-18 10:54:16 -08:00
name : String ,
2019-11-10 13:13:18 -06:00
/// Expected.
2019-01-29 13:04:42 -08:00
expected : GlobalDescriptor ,
2019-11-10 13:13:18 -06:00
/// Found.
2019-01-29 13:04:42 -08:00
found : GlobalDescriptor ,
2019-01-18 10:54:16 -08:00
} ,
2019-11-10 13:13:18 -06:00
/// A generic error with a message.
2019-08-07 15:40:42 -06:00
Generic {
2019-11-10 13:13:18 -06:00
/// Error message.
2019-08-07 15:40:42 -06:00
message : String ,
} ,
2019-01-18 10:54:16 -08:00
}
impl PartialEq for LinkError {
fn eq ( & self , _other : & LinkError ) -> bool {
false
}
}
2019-02-14 18:40:52 -08:00
impl std ::fmt ::Display for LinkError {
fn fmt ( & self , f : & mut std ::fmt ::Formatter ) -> std ::fmt ::Result {
match self {
LinkError ::ImportNotFound { namespace , name } = > write! ( f , " Import not found, namespace: {}, name: {} " , namespace , name ) ,
LinkError ::IncorrectGlobalDescriptor { namespace , name , expected , found } = > {
write! ( f , " Incorrect global descriptor, namespace: {}, name: {}, expected global descriptor: {:?}, found global descriptor: {:?} " , namespace , name , expected , found )
} ,
LinkError ::IncorrectImportSignature { namespace , name , expected , found } = > {
write! ( f , " Incorrect import signature, namespace: {}, name: {}, expected signature: {}, found signature: {} " , namespace , name , expected , found )
}
LinkError ::IncorrectImportType { namespace , name , expected , found } = > {
write! ( f , " Incorrect import type, namespace: {}, name: {}, expected type: {}, found type: {} " , namespace , name , expected , found )
}
LinkError ::IncorrectMemoryDescriptor { namespace , name , expected , found } = > {
write! ( f , " Incorrect memory descriptor, namespace: {}, name: {}, expected memory descriptor: {:?}, found memory descriptor: {:?} " , namespace , name , expected , found )
} ,
LinkError ::IncorrectTableDescriptor { namespace , name , expected , found } = > {
write! ( f , " Incorrect table descriptor, namespace: {}, name: {}, expected table descriptor: {:?}, found table descriptor: {:?} " , namespace , name , expected , found )
} ,
2019-08-07 15:40:42 -06:00
LinkError ::Generic { message } = > {
write! ( f , " {} " , message )
} ,
2019-02-14 18:40:52 -08:00
}
}
}
impl std ::error ::Error for LinkError { }
2019-01-18 10:54:16 -08:00
/// This is the error type returned when calling
2019-05-13 11:18:57 -07:00
/// a WebAssembly function.
2019-01-18 10:54:16 -08:00
///
/// The main way to do this is `Instance.call`.
///
/// Comparing two `RuntimeError`s always evaluates to false.
pub enum RuntimeError {
2019-11-10 13:13:18 -06:00
/// Trap.
Trap {
/// Trap message.
msg : Box < str > ,
} ,
/// Error.
Error {
/// Error data.
data : Box < dyn Any > ,
} ,
2019-01-18 10:54:16 -08:00
}
impl PartialEq for RuntimeError {
fn eq ( & self , _other : & RuntimeError ) -> bool {
false
}
}
2019-02-15 08:15:57 -08:00
impl std ::fmt ::Display for RuntimeError {
fn fmt ( & self , f : & mut std ::fmt ::Formatter ) -> std ::fmt ::Result {
match self {
2019-03-04 12:57:26 -08:00
RuntimeError ::Trap { ref msg } = > {
2019-08-01 12:15:11 -07:00
write! ( f , " WebAssembly trap occurred during runtime: {} " , msg )
2019-02-15 08:15:57 -08:00
}
2019-04-22 11:42:52 -07:00
RuntimeError ::Error { data } = > {
2019-04-22 15:06:40 -07:00
if let Some ( s ) = data . downcast_ref ::< String > ( ) {
write! ( f , " \" {} \" " , s )
2019-04-01 17:50:53 -07:00
} else if let Some ( s ) = data . downcast_ref ::< & str > ( ) {
2019-04-22 15:06:40 -07:00
write! ( f , " \" {} \" " , s )
2019-04-01 17:50:53 -07:00
} else {
2019-04-22 15:06:40 -07:00
write! ( f , " unknown error " )
}
2019-04-01 17:50:53 -07:00
}
2019-02-15 08:15:57 -08:00
}
}
}
2019-04-01 17:50:53 -07:00
impl std ::fmt ::Debug for RuntimeError {
fn fmt ( & self , f : & mut std ::fmt ::Formatter ) -> std ::fmt ::Result {
write! ( f , " {} " , self )
}
}
2019-02-15 08:15:57 -08:00
impl std ::error ::Error for RuntimeError { }
2019-01-23 15:30:35 -08:00
/// This error type is produced by resolving a wasm function
/// given its name.
///
/// Comparing two `ResolveError`s always evaluates to false.
#[ derive(Debug, Clone) ]
pub enum ResolveError {
2019-11-10 13:13:18 -06:00
/// Found signature did not match expected signature.
Signature {
/// Expected `FuncSig`.
expected : FuncSig ,
/// Found type.
found : Vec < Type > ,
} ,
/// Export not found.
ExportNotFound {
/// Name.
name : String ,
} ,
/// Export found with the wrong type.
ExportWrongType {
/// Name.
name : String ,
} ,
2019-01-23 15:30:35 -08:00
}
impl PartialEq for ResolveError {
fn eq ( & self , _other : & ResolveError ) -> bool {
false
}
}
2019-02-14 18:19:18 -08:00
impl std ::fmt ::Display for ResolveError {
fn fmt ( & self , f : & mut std ::fmt ::Formatter ) -> std ::fmt ::Result {
match self {
ResolveError ::ExportNotFound { name } = > write! ( f , " Export not found: {} " , name ) ,
ResolveError ::ExportWrongType { name } = > write! ( f , " Export wrong type: {} " , name ) ,
ResolveError ::Signature { expected , found } = > {
let found = found
. as_slice ( )
. iter ( )
. map ( | p | p . to_string ( ) )
. collect ::< Vec < _ > > ( )
. join ( " , " ) ;
let expected : & FuncSig = expected . borrow ( ) ;
write! (
f ,
" Parameters of type [{}] did not match signature {} " ,
found , expected
)
}
}
}
}
impl std ::error ::Error for ResolveError { }
2019-01-18 10:54:16 -08:00
/// This error type is produced by calling a wasm function
/// exported from a module.
///
/// If the module traps in some way while running, this will
/// be the `CallError::Runtime(RuntimeError)` variant.
///
/// Comparing two `CallError`s always evaluates to false.
pub enum CallError {
2019-11-10 13:13:18 -06:00
/// An error occured resolving the functions name or types.
2019-01-23 15:30:35 -08:00
Resolve ( ResolveError ) ,
2019-11-10 13:13:18 -06:00
/// A runtime error occurred during the function call.
2019-01-18 10:54:16 -08:00
Runtime ( RuntimeError ) ,
}
impl PartialEq for CallError {
fn eq ( & self , _other : & CallError ) -> bool {
false
}
}
2019-02-15 08:15:57 -08:00
impl std ::fmt ::Display for CallError {
fn fmt ( & self , f : & mut std ::fmt ::Formatter ) -> std ::fmt ::Result {
match self {
CallError ::Resolve ( resolve_error ) = > write! ( f , " Call error: {} " , resolve_error ) ,
CallError ::Runtime ( runtime_error ) = > write! ( f , " Call error: {} " , runtime_error ) ,
}
}
}
2019-04-01 17:50:53 -07:00
impl std ::fmt ::Debug for CallError {
fn fmt ( & self , f : & mut std ::fmt ::Formatter ) -> std ::fmt ::Result {
match self {
CallError ::Resolve ( resolve_err ) = > write! ( f , " ResolveError: {:?} " , resolve_err ) ,
CallError ::Runtime ( runtime_err ) = > write! ( f , " RuntimeError: {:?} " , runtime_err ) ,
}
}
}
2019-02-15 19:16:19 -06:00
impl std ::error ::Error for CallError { }
2019-01-29 15:44:15 -08:00
/// This error type is produced when creating something,
/// like a `Memory` or a `Table`.
#[ derive(Debug, Clone) ]
pub enum CreationError {
2019-11-10 13:13:18 -06:00
/// Unable to create memory error.
2019-01-29 15:44:15 -08:00
UnableToCreateMemory ,
2019-11-10 13:13:18 -06:00
/// Unable to create table error.
2019-01-29 15:44:15 -08:00
UnableToCreateTable ,
2019-11-10 13:13:18 -06:00
/// Invalid descriptor error with message.
2019-02-15 13:14:42 -08:00
InvalidDescriptor ( String ) ,
2019-01-29 15:44:15 -08:00
}
impl PartialEq for CreationError {
fn eq ( & self , _other : & CreationError ) -> bool {
false
}
}
2019-02-14 19:22:19 -08:00
impl std ::fmt ::Display for CreationError {
fn fmt ( & self , f : & mut std ::fmt ::Formatter ) -> std ::fmt ::Result {
match self {
CreationError ::UnableToCreateMemory = > write! ( f , " Unable to Create Memory " ) ,
CreationError ::UnableToCreateTable = > write! ( f , " Unable to Create Table " ) ,
2019-02-15 13:14:42 -08:00
CreationError ::InvalidDescriptor ( msg ) = > write! (
f ,
" Unable to create because the supplied descriptor is invalid: \" {} \" " ,
msg
) ,
2019-02-14 19:22:19 -08:00
}
}
}
impl std ::error ::Error for CreationError { }
2019-01-18 10:54:16 -08:00
/// The amalgamation of all errors that can occur
/// during the compilation, instantiation, or execution
2019-05-13 11:18:57 -07:00
/// of a WebAssembly module.
2019-01-18 10:54:16 -08:00
///
/// Comparing two `Error`s always evaluates to false.
2019-03-04 12:57:26 -08:00
#[ derive(Debug) ]
2019-01-18 10:54:16 -08:00
pub enum Error {
2019-11-10 13:13:18 -06:00
/// Compile error.
2019-01-18 10:54:16 -08:00
CompileError ( CompileError ) ,
2019-11-10 13:13:18 -06:00
/// Link errors.
2019-01-18 13:44:44 -08:00
LinkError ( Vec < LinkError > ) ,
2019-11-10 13:13:18 -06:00
/// Runtime error.
2019-01-18 10:54:16 -08:00
RuntimeError ( RuntimeError ) ,
2019-11-10 13:13:18 -06:00
/// Resolve error.
2019-01-24 10:51:20 -08:00
ResolveError ( ResolveError ) ,
2019-11-10 13:13:18 -06:00
/// Call error.
2019-01-18 10:54:16 -08:00
CallError ( CallError ) ,
2019-11-10 13:13:18 -06:00
/// Creation error.
2019-01-29 15:44:15 -08:00
CreationError ( CreationError ) ,
2019-01-18 10:54:16 -08:00
}
impl PartialEq for Error {
fn eq ( & self , _other : & Error ) -> bool {
false
}
}
2019-02-02 15:28:50 -08:00
impl From < CompileError > for Error {
2019-01-23 15:30:35 -08:00
fn from ( compile_err : CompileError ) -> Self {
2019-02-02 15:28:50 -08:00
Error ::CompileError ( compile_err )
2019-01-23 15:30:35 -08:00
}
}
2019-02-02 15:28:50 -08:00
impl From < RuntimeError > for Error {
2019-01-23 15:30:35 -08:00
fn from ( runtime_err : RuntimeError ) -> Self {
2019-02-02 15:28:50 -08:00
Error ::RuntimeError ( runtime_err )
2019-01-23 15:30:35 -08:00
}
}
2019-02-02 16:02:28 -08:00
impl From < ResolveError > for Error {
fn from ( resolve_err : ResolveError ) -> Self {
Error ::ResolveError ( resolve_err )
}
}
2019-02-02 15:28:50 -08:00
impl From < CallError > for Error {
2019-01-23 15:30:35 -08:00
fn from ( call_err : CallError ) -> Self {
2019-02-02 15:28:50 -08:00
Error ::CallError ( call_err )
2019-01-23 15:30:35 -08:00
}
}
2019-02-02 15:28:50 -08:00
impl From < CreationError > for Error {
2019-01-29 15:44:15 -08:00
fn from ( creation_err : CreationError ) -> Self {
2019-02-02 15:28:50 -08:00
Error ::CreationError ( creation_err )
}
}
impl From < Vec < LinkError > > for Error {
fn from ( link_errs : Vec < LinkError > ) -> Self {
Error ::LinkError ( link_errs )
2019-01-29 15:44:15 -08:00
}
}
2019-02-02 15:28:50 -08:00
impl From < RuntimeError > for CallError {
2019-01-23 15:30:35 -08:00
fn from ( runtime_err : RuntimeError ) -> Self {
2019-02-02 15:28:50 -08:00
CallError ::Runtime ( runtime_err )
2019-01-23 15:30:35 -08:00
}
}
2019-02-02 15:28:50 -08:00
impl From < ResolveError > for CallError {
2019-01-23 15:30:35 -08:00
fn from ( resolve_err : ResolveError ) -> Self {
2019-02-02 15:28:50 -08:00
CallError ::Resolve ( resolve_err )
2019-01-23 15:30:35 -08:00
}
}
2019-02-15 08:15:57 -08:00
impl std ::fmt ::Display for Error {
fn fmt ( & self , f : & mut std ::fmt ::Formatter ) -> std ::fmt ::Result {
2019-02-23 17:00:03 +08:00
match self {
Error ::CompileError ( err ) = > write! ( f , " compile error: {} " , err ) ,
Error ::LinkError ( errs ) = > {
if errs . len ( ) = = 1 {
write! ( f , " link error: {} " , errs [ 0 ] )
} else {
write! ( f , " {} link errors: " , errs . len ( ) ) ? ;
for ( i , err ) in errs . iter ( ) . enumerate ( ) {
write! ( f , " ({} of {}) {} " , i + 1 , errs . len ( ) , err ) ? ;
}
Ok ( ( ) )
}
2019-02-25 12:25:28 -08:00
}
2019-02-23 17:00:03 +08:00
Error ::RuntimeError ( err ) = > write! ( f , " runtime error: {} " , err ) ,
Error ::ResolveError ( err ) = > write! ( f , " resolve error: {} " , err ) ,
Error ::CallError ( err ) = > write! ( f , " call error: {} " , err ) ,
Error ::CreationError ( err ) = > write! ( f , " creation error: {} " , err ) ,
}
2019-02-15 08:15:57 -08:00
}
}
impl std ::error ::Error for Error { }
2019-02-22 22:18:59 -08:00
2019-11-10 13:13:18 -06:00
/// An error occurred while growing a memory or table.
2019-02-22 22:18:59 -08:00
#[ derive(Debug) ]
pub enum GrowError {
2019-11-10 13:13:18 -06:00
/// Error growing memory.
2019-02-22 22:18:59 -08:00
MemoryGrowError ,
2019-11-10 13:13:18 -06:00
/// Error growing table.
2019-02-22 22:18:59 -08:00
TableGrowError ,
2019-11-10 13:13:18 -06:00
/// Max pages were exceeded.
2019-02-22 22:18:59 -08:00
ExceededMaxPages ( PageError ) ,
2019-11-10 13:13:18 -06:00
/// Max pages for memory were exceeded.
2019-02-22 22:18:59 -08:00
ExceededMaxPagesForMemory ( usize , usize ) ,
2019-11-10 13:13:18 -06:00
/// Error protecting memory.
2019-02-22 22:18:59 -08:00
CouldNotProtectMemory ( MemoryProtectionError ) ,
2019-11-10 13:13:18 -06:00
/// Error creating memory.
2019-02-22 22:18:59 -08:00
CouldNotCreateMemory ( MemoryCreationError ) ,
}
impl std ::fmt ::Display for GrowError {
fn fmt ( & self , f : & mut std ::fmt ::Formatter ) -> std ::fmt ::Result {
match self {
GrowError ::MemoryGrowError = > write! ( f , " Unable to grow memory " ) ,
GrowError ::TableGrowError = > write! ( f , " Unable to grow table " ) ,
GrowError ::ExceededMaxPages ( e ) = > write! ( f , " Grow Error: {} " , e ) ,
GrowError ::ExceededMaxPagesForMemory ( left , added ) = > write! ( f , " Failed to add pages because would exceed maximum number of pages for the memory. Left: {}, Added: {} " , left , added ) ,
GrowError ::CouldNotCreateMemory ( e ) = > write! ( f , " Grow Error: {} " , e ) ,
GrowError ::CouldNotProtectMemory ( e ) = > write! ( f , " Grow Error: {} " , e ) ,
}
}
}
impl std ::error ::Error for GrowError { }
2019-11-10 13:13:18 -06:00
/// A kind of page error.
2019-02-22 22:18:59 -08:00
#[ derive(Debug) ]
pub enum PageError {
// left, right, added
2019-11-10 13:13:18 -06:00
/// Max pages were exceeded error.
2019-02-22 22:18:59 -08:00
ExceededMaxPages ( usize , usize , usize ) ,
}
impl std ::fmt ::Display for PageError {
fn fmt ( & self , f : & mut std ::fmt ::Formatter ) -> std ::fmt ::Result {
match self {
PageError ::ExceededMaxPages ( left , right , added ) = > write! ( f , " Failed to add pages because would exceed maximum number of pages. Left: {}, Right: {}, Pages added: {} " , left , right , added ) ,
}
}
}
impl std ::error ::Error for PageError { }
impl Into < GrowError > for PageError {
fn into ( self ) -> GrowError {
GrowError ::ExceededMaxPages ( self )
}
}
2019-11-10 13:13:18 -06:00
/// Error occured while creating memory.
2019-02-22 22:18:59 -08:00
#[ derive(Debug) ]
pub enum MemoryCreationError {
2019-11-10 13:13:18 -06:00
/// Allocation of virtual memory failed error.
2019-02-22 22:18:59 -08:00
VirtualMemoryAllocationFailed ( usize , String ) ,
2019-11-10 13:13:18 -06:00
/// Error creating memory from file.
2019-02-22 22:18:59 -08:00
CouldNotCreateMemoryFromFile ( std ::io ::Error ) ,
}
impl std ::fmt ::Display for MemoryCreationError {
fn fmt ( & self , f : & mut std ::fmt ::Formatter ) -> std ::fmt ::Result {
match self {
MemoryCreationError ::VirtualMemoryAllocationFailed ( size , msg ) = > write! (
f ,
" Allocation virtual memory with size {} failed. \n Errno message: {} " ,
size , msg
) ,
MemoryCreationError ::CouldNotCreateMemoryFromFile ( e ) = > write! ( f , " IO Error: {} " , e ) ,
}
}
}
impl std ::error ::Error for MemoryCreationError { }
impl Into < GrowError > for MemoryCreationError {
fn into ( self ) -> GrowError {
GrowError ::CouldNotCreateMemory ( self )
}
}
impl From < std ::io ::Error > for MemoryCreationError {
fn from ( io_error : std ::io ::Error ) -> Self {
MemoryCreationError ::CouldNotCreateMemoryFromFile ( io_error )
}
}
2019-11-10 13:13:18 -06:00
/// Error protecting memory.
2019-02-22 22:18:59 -08:00
#[ derive(Debug) ]
pub enum MemoryProtectionError {
2019-11-10 13:13:18 -06:00
/// Protection failed error.
2019-02-22 22:18:59 -08:00
ProtectionFailed ( usize , usize , String ) ,
}
impl std ::fmt ::Display for MemoryProtectionError {
fn fmt ( & self , f : & mut std ::fmt ::Formatter ) -> std ::fmt ::Result {
match self {
MemoryProtectionError ::ProtectionFailed ( start , size , msg ) = > write! (
f ,
" Allocation virtual memory starting at {} with size {} failed. \n Errno message: {} " ,
start , size , msg
) ,
}
}
}
impl std ::error ::Error for MemoryProtectionError { }
impl Into < GrowError > for MemoryProtectionError {
fn into ( self ) -> GrowError {
GrowError ::CouldNotProtectMemory ( self )
}
}
2019-03-12 10:45:44 -07:00
2019-11-10 13:13:18 -06:00
/// Parse Error.
2019-03-12 10:45:44 -07:00
#[ derive(Debug) ]
pub enum ParseError {
2019-11-10 13:13:18 -06:00
/// Error reading binary.
2019-03-12 10:45:44 -07:00
BinaryReadError ,
}
impl From < wasmparser ::BinaryReaderError > for ParseError {
fn from ( _ : wasmparser ::BinaryReaderError ) -> Self {
ParseError ::BinaryReadError
}
}