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
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use crate::{Binary, HumanAddr};
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum SystemError {
InvalidRequest { error: String, request: Binary },
InvalidResponse { error: String, response: Binary },
NoSuchContract { addr: HumanAddr },
Unknown {},
UnsupportedRequest { kind: String },
ExceededRecursionLimit {},
}
impl std::error::Error for SystemError {}
impl std::fmt::Display for SystemError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
SystemError::InvalidRequest { error, request } => write!(
f,
"Cannot parse request: {} in: {}",
error,
String::from_utf8_lossy(request.as_slice())
),
SystemError::InvalidResponse { error, response } => write!(
f,
"Cannot parse response: {} in: {}",
error,
String::from_utf8_lossy(response.as_slice())
),
SystemError::NoSuchContract { addr } => write!(f, "No such contract: {}", addr),
SystemError::Unknown {} => write!(f, "Unknown system error"),
SystemError::UnsupportedRequest { kind } => {
write!(f, "Unsupported query type: {}", kind)
}
SystemError::ExceededRecursionLimit {} => write!(f, "Query recursion limit exceeded"),
}
}
}
pub type SystemResult<T> = Result<T, SystemError>;