-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathinstructionerrors.rs
More file actions
39 lines (35 loc) · 1.2 KB
/
instructionerrors.rs
File metadata and controls
39 lines (35 loc) · 1.2 KB
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
use parity_wasm::elements::Instruction;
use std::error;
use std::fmt;
#[derive(Debug)]
pub enum InstructionError {
GlobalNotFound,
LocalNotFound,
UnmatchedInstruction,
InvalidOperation(Instruction),
}
impl fmt::Display for InstructionError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
InstructionError::GlobalNotFound => write!(f, "Global not found"),
InstructionError::LocalNotFound => write!(f, "Local not found"),
InstructionError::UnmatchedInstruction => write!(f, "Unmatched instruction"),
InstructionError::InvalidOperation(i) => {
write!(f, "{}", format!("Invalid operation: {:?}", i).as_str())
}
}
}
}
impl error::Error for InstructionError {
fn description(&self) -> &str {
match self {
InstructionError::GlobalNotFound => "Global not found",
InstructionError::LocalNotFound => "Local not found",
InstructionError::UnmatchedInstruction => "Unmatched instruction",
InstructionError::InvalidOperation(_) => "Invalid operation",
}
}
fn cause(&self) -> Option<&error::Error> {
None
}
}