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
#![feature(test)]
pub mod codec;
pub mod fixed_codec;
pub mod traits;
pub mod types;
use std::error::Error;
pub use bytes::{Buf, BufMut, Bytes, BytesMut};
use derive_more::{Constructor, Display};
#[derive(Debug, Clone)]
pub enum ProtocolErrorKind {
API,
Consensus,
Executor,
Mempool,
Network,
Storage,
Runtime,
Binding,
BindingMacro,
Service,
Main,
Codec,
FixedCodec,
Types,
}
#[derive(Debug, Constructor, Display)]
#[display(fmt = "[ProtocolError] Kind: {:?} Error: {:?}", kind, error)]
pub struct ProtocolError {
kind: ProtocolErrorKind,
error: Box<dyn Error + Send>,
}
impl From<ProtocolError> for Box<dyn Error + Send> {
fn from(error: ProtocolError) -> Self {
Box::new(error) as Box<dyn Error + Send>
}
}
impl Error for ProtocolError {}
pub type ProtocolResult<T> = Result<T, ProtocolError>;