Skip to main content

khive_fold/
error.rs

1//! Error types for khive-fold
2
3use thiserror::Error;
4use uuid::Uuid;
5
6/// Result type for fold operations
7pub type FoldResult<T> = std::result::Result<T, FoldError>;
8
9/// Errors that can occur in fold operations
10#[derive(Error, Debug)]
11pub enum FoldError {
12    /// Entry not found
13    #[error("Entry {0} not found")]
14    EntryNotFound(Uuid),
15
16    /// Invalid entry type for this fold
17    #[error("Invalid entry type: expected {expected}, got {actual}")]
18    InvalidEntryType {
19        /// The expected entry type name
20        expected: String,
21        /// The actual entry type that was provided
22        actual: String,
23    },
24
25    /// Fold context error
26    #[error("Context error: {0}")]
27    Context(String),
28
29    /// Serialization error
30    #[error("Serialization error: {0}")]
31    Serialization(#[from] serde_json::Error),
32
33    /// Storage error
34    #[error("Storage error: {0}")]
35    Storage(String),
36
37    /// Internal lock poisoned (concurrent panic)
38    #[error("Internal lock poisoned: {0}")]
39    LockPoisoned(String),
40
41    /// Invalid input to a cognitive primitive (Anchor, Selector).
42    #[error("invalid input: {0}")]
43    InvalidInput(String),
44
45    /// Budget exhausted during selection.
46    #[error("budget exhausted: needed {needed}, have {budget}")]
47    BudgetExhausted {
48        /// Budget needed.
49        needed: usize,
50        /// Budget available.
51        budget: usize,
52    },
53
54    /// Anchor not found during graph traversal.
55    #[error("anchor not found: {0}")]
56    AnchorNotFound(String),
57
58    /// Required component not configured.
59    #[error("required component not configured: {0}")]
60    ComponentMissing(String),
61
62    /// Checkpoint integrity check failed: stored hash does not match recomputed hash.
63    #[error("checkpoint integrity mismatch for '{id}': stored {stored}, computed {computed}")]
64    IntegrityMismatch {
65        /// Checkpoint id that failed verification.
66        id: String,
67        /// The hash stored in the checkpoint.
68        stored: String,
69        /// The hash recomputed from the loaded state.
70        computed: String,
71    },
72
73    /// A checkpoint with the given id was not found.
74    #[error("checkpoint not found: {0}")]
75    CheckpointNotFound(String),
76}
77
78#[cfg(test)]
79#[path = "error_tests.rs"]
80mod tests;