microsandbox_metrics/error.rs
1//! Error type used by the metrics registry.
2
3//--------------------------------------------------------------------------------------------------
4// Types
5//--------------------------------------------------------------------------------------------------
6
7/// Result alias for metrics operations.
8pub type MetricsResult<T> = Result<T, MetricsError>;
9
10/// Errors produced by the metrics registry.
11#[derive(Debug, thiserror::Error)]
12pub enum MetricsError {
13 /// Underlying I/O failure (typically from `shm_open`/`mmap`).
14 #[error("io error: {0}")]
15 Io(#[from] std::io::Error),
16
17 /// The registry already exists. Used internally for the create-or-open
18 /// race; callers rarely see this directly.
19 #[error("registry already exists")]
20 AlreadyExists,
21
22 /// No free slots are available.
23 #[error("metrics registry full")]
24 Full,
25
26 /// A slot's generation does not match the caller's expectation.
27 #[error("generation mismatch: expected {expected}, observed {actual}")]
28 GenerationMismatch {
29 /// Generation the caller believed it owned.
30 expected: u64,
31 /// Generation currently stored in the slot.
32 actual: u64,
33 },
34
35 /// Anything else worth surfacing as a string.
36 #[error("{0}")]
37 Custom(String),
38}