nodedb_graph/error.rs
1//! Typed error enum for the shared graph engine.
2//!
3//! Every fallible operation on `CsrIndex` (label interning, edge insert,
4//! edge delete) returns `Result<T, GraphError>`. The skill / CLAUDE.md
5//! discipline is explicit: silent casts or `debug_assert!` at capacity
6//! boundaries reproduce the same class of bug as the one being fixed —
7//! loud, typed errors only.
8
9use thiserror::Error;
10
11/// Hard upper bound on the number of distinct edge labels an individual
12/// `CsrIndex` can intern. `u32::MAX` is the type-theoretic ceiling;
13/// leaving one slot unused lets callers use `u32::MAX` as an "invalid"
14/// sentinel should they need it.
15pub const MAX_EDGE_LABELS: usize = (u32::MAX - 1) as usize;
16
17/// Errors returned by graph-engine operations.
18#[derive(Debug, Error)]
19pub enum GraphError {
20 /// The CSR's edge-label id space is exhausted. Happens only when
21 /// more than `MAX_EDGE_LABELS` distinct labels have been interned
22 /// — in practice unreachable because the DSL ingress caps label
23 /// length and realistic workloads use orders of magnitude fewer
24 /// labels. Surfaced here so the failure mode is a typed error, not
25 /// a silent wrap (the bug this crate was shipping before).
26 #[error("CSR edge-label id space exhausted ({used}/{MAX_EDGE_LABELS} labels interned)")]
27 LabelOverflow { used: usize },
28}