Skip to main content

zlayer_overlayd/
error.rs

1//! Error type for the overlayd transport, server, and client.
2
3use thiserror::Error;
4
5/// Maximum accepted IPC frame size (8 MiB). A status snapshot of a large
6/// cluster is the biggest legitimate frame; anything past this is treated as a
7/// framing desync / hostile peer and rejected rather than allocated.
8pub const MAX_FRAME_BYTES: usize = 8 * 1024 * 1024;
9
10/// Errors raised by the overlayd IPC layer and server.
11#[derive(Debug, Error)]
12pub enum OverlaydError {
13    /// Underlying socket / pipe I/O error.
14    #[error("io error: {0}")]
15    Io(#[from] std::io::Error),
16    /// JSON (de)serialization of a frame failed.
17    #[error("frame codec error: {0}")]
18    Codec(#[from] serde_json::Error),
19    /// A frame exceeded [`MAX_FRAME_BYTES`].
20    #[error("frame too large: {0} bytes (max {MAX_FRAME_BYTES})")]
21    FrameTooLarge(usize),
22    /// The peer closed the connection.
23    #[error("connection closed by peer")]
24    Closed,
25    /// The overlay engine reported a failure (wraps the human-readable reason
26    /// that crosses the wire in `OverlaydResponse::Err`).
27    #[error("overlay engine error: {0}")]
28    Overlay(String),
29    /// Any other error with a message.
30    #[error("{0}")]
31    Other(String),
32}
33
34/// Convenience result alias for the overlayd crate.
35pub type Result<T> = std::result::Result<T, OverlaydError>;