Skip to main content

cpop_protocol/
error.rs

1// SPDX-License-Identifier: Apache-2.0
2
3use thiserror::Error;
4
5/// Alias for `std::result::Result` with the protocol `Error` type.
6pub type Result<T> = std::result::Result<T, Error>;
7
8#[derive(Debug, Error)]
9pub enum Error {
10    /// Wrap a `std::io::Error`.
11    #[error("i/o error: {0}")]
12    Io(#[from] std::io::Error),
13
14    /// CBOR/JSON serialization or deserialization failure.
15    #[error("serialization error: {0}")]
16    Serialization(String),
17
18    /// Signing, verification, or HMAC computation failure.
19    #[error("cryptographic error: {0}")]
20    Crypto(String),
21
22    /// Wire-format or state-machine protocol violation.
23    #[error("protocol violation: {0}")]
24    Protocol(String),
25
26    #[error("validation failed: {0}")]
27    Validation(String),
28
29    #[error("unknown error: {0}")]
30    Unknown(String),
31}