-
Notifications
You must be signed in to change notification settings - Fork 689
/
Copy patherrors.rs
90 lines (84 loc) · 3.49 KB
/
errors.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
use near_vm_errors::{CompilationError, FunctionCallError, MethodResolveError, VMError};
use near_vm_logic::VMLogicError;
pub trait IntoVMError {
fn into_vm_error(self) -> VMError;
}
impl IntoVMError for wasmer_runtime::error::Error {
fn into_vm_error(self) -> VMError {
use wasmer_runtime::error::Error;
match self {
Error::CompileError(err) => err.into_vm_error(),
Error::LinkError(err) => VMError::FunctionCallError(FunctionCallError::LinkError {
msg: format!("{:.500}", Error::LinkError(err).to_string()),
}),
Error::RuntimeError(err) => err.into_vm_error(),
Error::ResolveError(err) => err.into_vm_error(),
Error::CallError(err) => err.into_vm_error(),
Error::CreationError(err) => panic!(err),
}
}
}
impl IntoVMError for wasmer_runtime::error::CallError {
fn into_vm_error(self) -> VMError {
use wasmer_runtime::error::CallError;
match self {
CallError::Resolve(err) => err.into_vm_error(),
CallError::Runtime(err) => err.into_vm_error(),
}
}
}
impl IntoVMError for wasmer_runtime::error::CompileError {
fn into_vm_error(self) -> VMError {
VMError::FunctionCallError(FunctionCallError::CompilationError(
CompilationError::WasmerCompileError { msg: self.to_string() },
))
}
}
impl IntoVMError for wasmer_runtime::error::ResolveError {
fn into_vm_error(self) -> VMError {
use wasmer_runtime::error::ResolveError as WasmerResolveError;
match self {
WasmerResolveError::Signature { .. } => VMError::FunctionCallError(
FunctionCallError::MethodResolveError(MethodResolveError::MethodInvalidSignature),
),
WasmerResolveError::ExportNotFound { .. } => VMError::FunctionCallError(
FunctionCallError::MethodResolveError(MethodResolveError::MethodNotFound),
),
WasmerResolveError::ExportWrongType { .. } => VMError::FunctionCallError(
FunctionCallError::MethodResolveError(MethodResolveError::MethodNotFound),
),
}
}
}
impl IntoVMError for wasmer_runtime::error::RuntimeError {
fn into_vm_error(self) -> VMError {
use wasmer_runtime::error::RuntimeError;
match &self {
RuntimeError::Trap { msg } => {
VMError::FunctionCallError(FunctionCallError::WasmTrap { msg: msg.to_string() })
}
RuntimeError::Error { data } => {
if let Some(err) = data.downcast_ref::<VMLogicError>() {
match err {
VMLogicError::HostError(h) => {
VMError::FunctionCallError(FunctionCallError::HostError(h.clone()))
}
VMLogicError::ExternalError(s) => VMError::ExternalError(s.clone()),
VMLogicError::InconsistentStateError(e) => {
VMError::InconsistentStateError(e.clone())
}
}
} else {
eprintln!(
"Bad error case! Output is non-deterministic {:?} {:?}",
data.type_id(),
self.to_string()
);
VMError::FunctionCallError(FunctionCallError::WasmTrap {
msg: "unknown".to_string(),
})
}
}
}
}
}