1use crate::id::MemoryId;
7
8#[derive(Debug, thiserror::Error)]
14pub enum MemoryError {
15 #[error("Memory item '{0}' not found")]
17 NotFound(MemoryId),
18
19 #[error("Working memory buffer is full (capacity: {capacity})")]
21 BufferFull { capacity: usize },
22
23 #[error("Serialization failed: {0}")]
25 Serialization(String),
26
27 #[error("Invalid confidence value {value}: must be in [0.0, 1.0]")]
29 InvalidConfidence { value: f32 },
30
31 #[error("Consolidation failed: {reason}")]
33 ConsolidationFailed { reason: String },
34
35 #[error("Conflict resolution rejected incoming fact")]
37 ConflictRejected,
38
39 #[error("Persistence error: {0}")]
41 Persistence(String),
42}
43
44#[cfg(test)]
45mod tests {
46 use super::*;
47 use crate::id::MemoryId;
48
49 #[test]
50 fn test_not_found_error_displays_id() {
51 let id = MemoryId::new();
52 let err = MemoryError::NotFound(id.clone());
53 let msg = err.to_string();
54 assert!(msg.contains(&id.to_string()), "expected id in message: {msg}");
55 }
56
57 #[test]
58 fn test_buffer_full_error_displays_capacity() {
59 let err = MemoryError::BufferFull { capacity: 42 };
60 assert!(err.to_string().contains("42"));
61 }
62
63 #[test]
64 fn test_invalid_confidence_error_displays_value() {
65 let err = MemoryError::InvalidConfidence { value: 1.5 };
66 assert!(err.to_string().contains("1.5"));
67 }
68
69 #[test]
70 fn test_consolidation_failed_error_displays_reason() {
71 let err = MemoryError::ConsolidationFailed {
72 reason: "no policies matched".into(),
73 };
74 assert!(err.to_string().contains("no policies matched"));
75 }
76
77 #[test]
78 fn test_conflict_rejected_error_has_message() {
79 let err = MemoryError::ConflictRejected;
80 assert!(!err.to_string().is_empty());
81 }
82
83 #[test]
84 fn test_persistence_error_displays_message() {
85 let err = MemoryError::Persistence("disk full".into());
86 assert!(err.to_string().contains("disk full"));
87 }
88
89 #[test]
90 fn test_serialization_error_display() {
91 let mem_err = MemoryError::Serialization("postcard: unexpected end of input".into());
92 assert!(mem_err.to_string().contains("Serialization"));
93 }
94}