Skip to main content

logfence_client/
error.rs

1//! Error types for the logfence client library.
2
3use thiserror::Error;
4
5// ── BuildError ────────────────────────────────────────────────────────────────
6
7/// Errors that occur while constructing a [`crate::MessageBuilder`].
8#[derive(Debug, Error)]
9pub enum BuildError {
10    /// A `kv` field key was the empty string.
11    #[error("field key must not be empty")]
12    EmptyKey,
13
14    /// A `kv` field value could not be serialized to JSON.
15    #[error("value serialization failed: {0}")]
16    Serialize(#[from] serde_json::Error),
17}
18
19// ── ClientError ───────────────────────────────────────────────────────────────
20
21/// Errors that occur while sending a syslog message.
22#[derive(Debug, Error)]
23pub enum ClientError {
24    /// The message construction step failed.
25    #[error("build error: {0}")]
26    Build(#[from] BuildError),
27
28    /// The rendered message exceeds the transport's size limit.
29    #[error("message size {got} bytes exceeds maximum of {max} bytes")]
30    MessageTooLarge { max: usize, got: usize },
31
32    /// An underlying I/O error (connection failure, broken pipe, etc.).
33    #[error("I/O error: {0}")]
34    Io(#[from] std::io::Error),
35}