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
use crate::*;
use errmap::{ErrorDescription, ErrorMapping};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct IDLErrorMapping {
pub error_categories: BTreeMap<u64, IDLError>,
pub module_error_maps: BTreeMap<ModuleIdData, BTreeMap<u64, IDLError>>,
}
impl From<ErrorMapping> for IDLErrorMapping {
fn from(errmap: ErrorMapping) -> Self {
IDLErrorMapping {
error_categories: errmap
.error_categories
.into_iter()
.map(|(k, v)| (k, IDLError::from(v)))
.collect(),
module_error_maps: errmap
.module_error_maps
.into_iter()
.map(|(k, v)| {
(
k,
v.into_iter().map(|(k, v)| (k, IDLError::from(v))).collect(),
)
})
.collect(),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct IDLError {
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub doc: Option<String>,
}
impl From<ErrorDescription> for IDLError {
fn from(desc: ErrorDescription) -> Self {
IDLError {
name: desc.code_name,
doc: if desc.code_description.is_empty() {
None
} else {
Some(desc.code_description)
},
}
}
}