summaryrefslogtreecommitdiff
path: root/crates/tor-congestion/src/err.rs
blob: d00c193bf5440278f81107d194b11ad8761fa075 (plain)
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
//! Error handling.

use thiserror::Error;
use tor_error::{ErrorKind, HasKind};

/// Result alias using this crate's error type.
pub type Result<T> = std::result::Result<T, Error>;

/// An error originating from the tor-congestion crate.
#[derive(Error, Debug, Clone)]
#[non_exhaustive]
pub enum Error {
    /// A call to `RoundtripTimeEstimator::sendme_received` was made without calling
    /// `RoundtripTimeEstimator::expect_sendme` first.
    #[error("Informed of a SENDME we weren't expecting")]
    MismatchedEstimationCall,
}

impl HasKind for Error {
    fn kind(&self) -> ErrorKind {
        use Error as E;
        match self {
            E::MismatchedEstimationCall => ErrorKind::TorProtocolViolation,
        }
    }
}