1use crate::sync::message::Throttled;
6use futures::channel::oneshot;
7use network;
8use rlp::DecoderError;
9use std::io;
10use thiserror::Error;
11
12#[derive(Debug, Error)]
13pub enum Error {
14 #[error(transparent)]
15 Network(#[from] network::Error),
16 #[error(transparent)]
17 Storage(#[from] cfx_storage::Error),
18 #[error(transparent)]
19 Decoder(#[from] DecoderError),
20 #[error(transparent)]
21 Io(#[from] io::Error),
22
23 #[error("Invalid block")]
24 InvalidBlock,
25 #[error("Invalid GetBlockTxn: {0}")]
26 InvalidGetBlockTxn(String),
27 #[error("Invalid message format")]
28 InvalidMessageFormat,
29 #[error("Invalid Status: {0}")]
30 InvalidStatus(String),
31 #[error("Unknown peer")]
32 UnknownPeer,
33 #[error("Unexpected response")]
34 UnexpectedResponse,
35 #[error("No matching request found for response")]
36 RequestNotFound,
37 #[error("Sent too many transactions")]
38 TooManyTrans,
39 #[error("Rpc gets timeout")]
40 RpcTimeout,
41 #[error("Rpc gets cancelled by disconnection")]
42 RpcCancelledByDisconnection,
43 #[error("Drift too much")]
44 InvalidTimestamp,
45 #[error("invalid snapshot manifest: {0}")]
46 InvalidSnapshotManifest(String),
47 #[error("invalid snapshot chunk: {0}")]
48 InvalidSnapshotChunk(String),
49 #[error("Receive an empty snapshot chunk response, retry later")]
50 EmptySnapshotChunk,
51 #[error("packet already throttled: {0:?}")]
52 AlreadyThrottled(&'static str),
53 #[error("packet {0:?} throttled: {1:?}")]
54 Throttled(&'static str, Throttled),
55 #[error("Cannot process the message due to the catch up mode: {0:?}")]
56 InCatchUpMode(String),
57 #[error("Internal error: {0:?}")]
58 InternalError(String),
59 #[error("UnexpectedMessage: {0:?}")]
60 UnexpectedMessage(String),
61 #[error(
62 "Unable to process the message due to protocol version mismatch: {0}"
63 )]
64 NotSupported(String),
65 #[error("error msg: {0}")]
66 Msg(String),
67}
68
69impl From<oneshot::Canceled> for Error {
70 fn from(error: oneshot::Canceled) -> Self {
71 Error::InternalError(format!("{}", error)).into()
72 }
73}
74
75impl From<String> for Error {
76 fn from(s: String) -> Error { Error::Msg(s) }
77}