mpc_protocol/
error.rs

1use thiserror::Error;
2
3/// Errors generated by the relay protocol.
4#[derive(Debug, Error)]
5pub enum Error {
6    /// Error generated a buffer is too large.
7    #[error("buffer exceeds maximum size {0}")]
8    MaxBufferSize(usize),
9
10    /// Error generated when encoding identity bytes are invalid.
11    #[error("encoding identity bytes are invalid")]
12    BadEncodingIdentity,
13
14    /// Error generated when encoding versions are mismatched.
15    #[error("encoding version is not supported, expecting version {0} but got version {1}")]
16    EncodingVersion(u16, u16),
17
18    /// Error generated decoding the kind for an encoding is invalid.
19    #[error("invalid encoding kind identifier {0}")]
20    EncodingKind(u8),
21
22    /// Error generated when the noise pattern in a PEM does not
23    /// match the pattern in use by the protocol.
24    #[error(r#"noise protocol pattern mismatch, expecting "{0}""#)]
25    PatternMismatch(String),
26
27    /// Error generated when the PEM encoding does not match
28    /// the expected format.
29    #[error("encoding in PEM is invalid")]
30    BadKeypairPem,
31
32    /// Error generated when a node expects to be in the transport
33    /// protocol state.
34    #[error("not transport protocol state")]
35    NotTransportState,
36
37    /// Error generated by input/output.
38    #[error(transparent)]
39    Io(#[from] std::io::Error),
40
41    /// Error generated by the noise protocol library.
42    #[error(transparent)]
43    Snow(#[from] snow::error::Error),
44
45    /// Error generated decoding PEM data.
46    #[error(transparent)]
47    Pem(#[from] pem::PemError),
48
49    /// Error generated serializing or deserializing JSON.
50    #[error(transparent)]
51    Json(#[from] serde_json::Error),
52}