use nodedb_mem::MemError;
use thiserror::Error;
pub const MAX_EDGE_LABELS: usize = (u32::MAX - 1) as usize;
pub const MAX_NODES_PER_CSR: usize = (u32::MAX - 1) as usize;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum GraphError {
#[error("CSR edge-label id space exhausted ({used}/{MAX_EDGE_LABELS} labels interned)")]
LabelOverflow { used: usize },
#[error(
"CSR node id space exhausted ({used}/{MAX_NODES_PER_CSR} nodes); \
collection must be sharded to accept more nodes"
)]
NodeOverflow { used: usize },
#[error("graph memory budget rejected: {0}")]
MemoryBudget(#[from] MemError),
#[error("cannot withdraw {kind} '{name}': it is not the newest {kind} or it is still in use")]
WithdrawRefused { kind: &'static str, name: String },
#[error("a rebuild of this CSR index is already running")]
RebuildInProgress,
#[error("the CSR index this rebuild started from is no longer live; rebuild discarded")]
RebuildSuperseded,
#[error(
"CSR writes during the rebuild exceeded the {cap_bytes}-byte journal bound; \
rebuild discarded, live index unchanged; run REINDEX again"
)]
RebuildJournalOverflow { cap_bytes: usize },
#[error("CSR rebuild replay of '{op}' diverged from the live index; rebuild discarded")]
RebuildReplayDiverged { op: &'static str },
#[error("CSR rebuild snapshot is invalid: {detail}")]
RebuildSnapshotInvalid { detail: String },
}