1use std::time::Duration;
4
5pub type Result<T> = std::result::Result<T, Error>;
7
8#[derive(Debug, thiserror::Error)]
10pub enum Error {
11 #[error("control message is too large: {actual} bytes (maximum {maximum})")]
13 ControlMessageTooLarge {
14 actual: usize,
16 maximum: usize,
18 },
19
20 #[error("no mutually supported protocol version")]
22 UnsupportedProtocolVersion,
23
24 #[error("test duration {requested:?} exceeds server limit {maximum:?}")]
26 DurationLimitExceeded {
27 requested: Duration,
29 maximum: Duration,
31 },
32
33 #[error("operation timed out during {stage}")]
35 Timeout {
36 stage: &'static str,
38 },
39
40 #[error("benchmark was cancelled")]
42 Cancelled,
43
44 #[error("peer policy denies throughput measurements")]
46 ThroughputDeniedByPeer,
47
48 #[error("peer error {code}: {message}")]
50 Peer {
51 code: u16,
53 message: String,
55 },
56
57 #[error("network error: {0}")]
59 Network(String),
60
61 #[error("measurement stream was stopped by the peer")]
63 FlowStopped,
64
65 #[error("protocol error: {0}")]
67 Protocol(String),
68
69 #[error("control codec error: {0}")]
71 Codec(#[from] postcard::Error),
72
73 #[error("I/O error: {0}")]
75 Io(#[from] std::io::Error),
76}
77
78impl Error {
79 pub(crate) fn network(error: impl std::fmt::Display) -> Self {
81 Self::Network(error.to_string())
82 }
83}