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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
use std::fmt;
use std::io;
#[repr(u32)]
#[derive(Debug, Clone, Copy)]
pub enum CallError {
Success = 0,
SerializationFailed = 1,
DeserializationFailed = 2,
InvalidWapm = 3,
FetchFailed = 4,
CompileError = 5,
IncorrectAbi = 6,
Aborted = 7,
InvalidHandle = 8,
InvalidTopic = 9,
MissingCallbacks = 10,
Unsupported = 11,
BadRequest = 12,
InternalFailure = 14,
MemoryAllocationFailed = 16,
BusInvocationFailed = 17,
Unknown = u32::MAX,
}
impl From<u32> for CallError {
fn from(val: u32) -> CallError {
match val {
0 => CallError::Success,
1 => CallError::SerializationFailed,
2 => CallError::DeserializationFailed,
3 => CallError::InvalidWapm,
4 => CallError::FetchFailed,
5 => CallError::CompileError,
6 => CallError::IncorrectAbi,
7 => CallError::Aborted,
8 => CallError::InvalidHandle,
9 => CallError::InvalidTopic,
10 => CallError::MissingCallbacks,
11 => CallError::Unsupported,
12 => CallError::BadRequest,
14 => CallError::InternalFailure,
16 => CallError::MemoryAllocationFailed,
17 => CallError::BusInvocationFailed,
_ => CallError::Unknown,
}
}
}
impl Into<u32> for CallError {
fn into(self) -> u32 {
match self {
CallError::Success => 0,
CallError::SerializationFailed => 1,
CallError::DeserializationFailed => 2,
CallError::InvalidWapm => 3,
CallError::FetchFailed => 4,
CallError::CompileError => 5,
CallError::IncorrectAbi => 6,
CallError::Aborted => 7,
CallError::InvalidHandle => 8,
CallError::InvalidTopic => 9,
CallError::MissingCallbacks => 10,
CallError::Unsupported => 11,
CallError::BadRequest => 12,
CallError::InternalFailure => 14,
CallError::MemoryAllocationFailed => 16,
CallError::BusInvocationFailed => 17,
CallError::Unknown => u32::MAX,
}
}
}
impl CallError {
pub fn into_io_error(self) -> io::Error {
self.into()
}
}
impl Into<io::Error> for CallError {
fn into(self) -> io::Error {
match self {
CallError::InvalidHandle => io::Error::new(
io::ErrorKind::ConnectionAborted,
format!("connection aborted - {}", self.to_string()).as_str(),
),
err => io::Error::new(
io::ErrorKind::Other,
format!("wasm bus error - {}", err.to_string()).as_str(),
),
}
}
}
impl fmt::Display for CallError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
CallError::Success => write!(f, "operation successful"),
CallError::SerializationFailed => write!(
f,
"there was an error while serializing the request or response."
),
CallError::DeserializationFailed => write!(
f,
"there was an error while deserializing the request or response."
),
CallError::InvalidWapm => write!(f, "the specified WAPM module does not exist."),
CallError::FetchFailed => write!(f, "failed to fetch the WAPM module."),
CallError::CompileError => write!(f, "failed to compile the WAPM module."),
CallError::IncorrectAbi => write!(f, "the ABI is invalid for cross module calls."),
CallError::Aborted => write!(f, "the request has been aborted."),
CallError::InvalidHandle => write!(f, "the handle is not valid."),
CallError::InvalidTopic => write!(f, "the topic name is invalid."),
CallError::MissingCallbacks => {
write!(f, "some mandatory callbacks were not registered.")
}
CallError::Unsupported => {
write!(f, "this operation is not supported on this platform.")
}
CallError::BadRequest => write!(
f,
"invalid input was supplied in the call resulting in a bad request."
),
CallError::InternalFailure => write!(f, "an internal failure has occured"),
CallError::MemoryAllocationFailed => write!(f, "memory allocation has failed"),
CallError::BusInvocationFailed => write!(f, "bus invocation has failed"),
CallError::Unknown => write!(f, "unknown error."),
}
}
}