microsandbox_protocol/error.rs
1//! Error types for the microsandbox-protocol crate.
2
3use thiserror::Error;
4
5//--------------------------------------------------------------------------------------------------
6// Types
7//--------------------------------------------------------------------------------------------------
8
9/// The result type for protocol operations.
10pub type ProtocolResult<T> = Result<T, ProtocolError>;
11
12/// Errors that can occur during protocol operations.
13#[derive(Debug, Error)]
14pub enum ProtocolError {
15 /// An I/O error.
16 #[error("io error: {0}")]
17 Io(#[from] std::io::Error),
18
19 /// A CBOR serialization error.
20 #[error("cbor encode error: {0}")]
21 CborEncode(#[from] ciborium::ser::Error<std::io::Error>),
22
23 /// A CBOR deserialization error.
24 #[error("cbor decode error: {0}")]
25 CborDecode(#[from] ciborium::de::Error<std::io::Error>),
26
27 /// The message frame exceeded the maximum allowed size.
28 #[error("frame too large: {size} bytes (max {max})")]
29 FrameTooLarge {
30 /// The size of the frame.
31 size: u32,
32 /// The maximum allowed size.
33 max: u32,
34 },
35
36 /// Unexpected end of stream.
37 #[error("unexpected end of stream")]
38 UnexpectedEof,
39}