Skip to main content

nodedb_mem/
error.rs

1// SPDX-License-Identifier: BUSL-1.1
2
3use crate::engine::EngineId;
4
5/// Errors produced by the memory governor.
6#[derive(Debug, thiserror::Error)]
7pub enum MemError {
8    /// Allocation request exceeds the engine's remaining budget.
9    #[error(
10        "memory budget exhausted for {engine:?}: requested {requested} bytes, \
11         available {available} bytes (limit: {limit} bytes)"
12    )]
13    BudgetExhausted {
14        engine: EngineId,
15        requested: usize,
16        available: usize,
17        limit: usize,
18    },
19
20    /// The global memory ceiling would be exceeded.
21    #[error(
22        "global memory ceiling exceeded: total allocated {allocated} bytes, \
23         ceiling {ceiling} bytes, requested {requested} bytes"
24    )]
25    GlobalCeilingExceeded {
26        allocated: usize,
27        ceiling: usize,
28        requested: usize,
29    },
30
31    /// Engine is not registered with the governor.
32    #[error("unknown engine: {0:?}")]
33    UnknownEngine(EngineId),
34
35    /// jemalloc introspection error.
36    #[error("jemalloc error: {0}")]
37    Jemalloc(String),
38}
39
40pub type Result<T> = std::result::Result<T, MemError>;