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
80
81
82
83
84
85
86
//! Error types.
use std::time::Duration;
/// Crate result type.
pub type Result<T> = std::result::Result<T, Error>;
/// Errors produced by a benchmark run.
#[derive(Debug, thiserror::Error)]
pub enum Error {
/// A control frame exceeded the configured maximum.
#[error("control message is too large: {actual} bytes (maximum {maximum})")]
ControlMessageTooLarge {
/// Encoded message size.
actual: usize,
/// Configured maximum.
maximum: usize,
},
/// The peer selected no mutually supported protocol version.
#[error("no mutually supported protocol version")]
UnsupportedProtocolVersion,
/// A requested test exceeds a server limit.
#[error("test duration {requested:?} exceeds server limit {maximum:?}")]
DurationLimitExceeded {
/// Requested duration.
requested: Duration,
/// Server maximum.
maximum: Duration,
},
/// The operation timed out.
#[error("operation timed out during {stage}")]
Timeout {
/// Human-readable stage name.
stage: &'static str,
},
/// The caller cancelled the benchmark task.
#[error("benchmark was cancelled")]
Cancelled,
/// The peer allows low-bandwidth probes but denies throughput measurements.
#[error("peer policy denies throughput measurements")]
ThroughputDeniedByPeer,
/// The peer rejected or failed a protocol operation.
#[error("peer error {code}: {message}")]
Peer {
/// Stable wire error code.
code: u16,
/// Diagnostic message.
message: String,
},
/// An iroh connection or stream operation failed.
#[error("network error: {0}")]
Network(String),
/// A protocol invariant was violated.
#[error("protocol error: {0}")]
Protocol(String),
/// The operation belongs to a later implementation phase.
#[error("{feature} is not implemented yet")]
NotImplemented {
/// Missing feature name.
feature: &'static str,
},
/// Control message serialization failed.
#[error("control codec error: {0}")]
Codec(#[from] postcard::Error),
/// I/O failed.
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
}
impl Error {
/// Converts an external network error without exposing it in the public error enum.
pub(crate) fn network(error: impl std::fmt::Display) -> Self {
Self::Network(error.to_string())
}
}