hopr_transport_protocol/
errors.rs1use hopr_api::types::{internal::errors::CoreTypesError, primitive::errors::GeneralError};
2use thiserror::Error;
3
4#[derive(Error, Debug)]
6pub enum ProtocolError {
7 #[error("timeout on protocol operation")]
8 Timeout,
9
10 #[error(transparent)]
11 Other(Box<dyn std::error::Error + Send + Sync + 'static>),
12
13 #[error("General error {0}")]
14 GeneralError(#[from] GeneralError),
15
16 #[error("Core error {0}")]
17 CoreError(#[from] CoreTypesError),
18
19 #[error("Failed on a logical error: {0}")]
20 Logic(String),
21}
22
23pub type Result<T> = core::result::Result<T, ProtocolError>;
25
26#[cfg(test)]
27mod tests {
28 use super::*;
29
30 #[test]
31 fn protocol_error_variants_should_display_correctly() {
32 let variants: Vec<String> = vec![
33 ProtocolError::Timeout.to_string(),
34 ProtocolError::Logic("test logic error".into()).to_string(),
35 ProtocolError::GeneralError(GeneralError::ParseError("bad parse".into())).to_string(),
36 ];
37 insta::assert_debug_snapshot!(variants);
38 }
39}