Skip to main content

zerodds_durability_store/
error.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 ZeroDDS Contributors
3
4//! Error type for the durability storage layer.
5
6use alloc::string::String;
7use core::fmt;
8
9/// Result alias for the durability store.
10pub type Result<T> = core::result::Result<T, StoreError>;
11
12/// Errors surfaced by a [`crate::DurabilityStore`].
13#[derive(Debug, Clone, PartialEq, Eq)]
14pub enum StoreError {
15    /// A QoS contract cap was reached (`max_samples`, `max_instances`,
16    /// `max_samples_per_instance` under `KEEP_ALL`). The caller maps this to a
17    /// `RESOURCE_LIMITS_EXCEEDED` event. Carries a static reason.
18    OutOfResources(&'static str),
19    /// Backend/adapter failure (I/O, sqlite, serialization). Carries an
20    /// owned message because adapter errors are dynamic.
21    Backend(String),
22    /// An internal lock was poisoned (a thread panicked while holding it).
23    Poisoned(&'static str),
24}
25
26impl fmt::Display for StoreError {
27    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28        match self {
29            Self::OutOfResources(w) => write!(f, "durability store: out of resources: {w}"),
30            Self::Backend(m) => write!(f, "durability store: backend error: {m}"),
31            Self::Poisoned(w) => write!(f, "durability store: lock poisoned: {w}"),
32        }
33    }
34}
35
36impl core::error::Error for StoreError {}