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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//! Error types for ant-node.
use thiserror::Error;
/// Result type alias using the crate's Error type.
pub type Result<T> = std::result::Result<T, Error>;
/// Errors that can occur in ant-node.
#[derive(Error, Debug)]
pub enum Error {
/// Configuration error.
#[error("configuration error: {0}")]
Config(String),
/// Node startup error.
#[error("node startup failed: {0}")]
Startup(String),
/// Network error from the core networking layer.
#[error("network error: {0}")]
Network(String),
/// Storage error.
#[error("storage error: {0}")]
Storage(String),
/// Payment error.
#[error("payment error: {0}")]
Payment(String),
/// Upgrade error.
#[error("upgrade error: {0}")]
Upgrade(String),
/// Cryptographic error.
#[error("crypto error: {0}")]
Crypto(String),
/// I/O error.
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
/// Serialization error.
#[error("serialization error: {0}")]
Serialization(String),
/// Protocol error.
#[error("protocol error: {0}")]
Protocol(String),
/// Invalid chunk error.
#[error("invalid chunk: {0}")]
InvalidChunk(String),
/// Replication error.
#[error("replication error: {0}")]
Replication(String),
/// Node is shutting down.
#[error("node is shutting down")]
ShuttingDown,
}
impl From<ant_protocol::pointer::PointerError> for Error {
/// Map a wire-level pointer rejection onto the node's error type.
///
/// Signature failures become [`Error::Crypto`] and everything else becomes
/// [`Error::Protocol`], so a caller can still tell "these bytes are not a
/// pointer" from "these bytes are not signed by the key they carry".
fn from(error: ant_protocol::pointer::PointerError) -> Self {
use ant_protocol::pointer::PointerError;
match error {
PointerError::SignatureInvalid | PointerError::SigningFailed(_) => {
Self::Crypto(error.to_string())
}
other => Self::Protocol(other.to_string()),
}
}
}