post_cortex_memory/
error.rs1use thiserror::Error;
11use uuid::Uuid;
12
13#[derive(Debug, Error)]
15pub enum Error {
16 #[error(transparent)]
18 Storage(#[from] post_cortex_storage::error::Error),
19
20 #[error(transparent)]
22 Embeddings(#[from] post_cortex_embeddings::error::Error),
23
24 #[error(transparent)]
26 Domain(#[from] post_cortex_core::SystemError),
27
28 #[error("session not found: {0}")]
30 SessionNotFound(Uuid),
31
32 #[error("circuit breaker open: {0}")]
35 CircuitBreaker(String),
36
37 #[error("pipeline backpressure on {queue}")]
39 Backpressure {
40 queue: &'static str,
42 },
43
44 #[error("pipeline worker shut down: {queue}")]
46 WorkerShutdown {
47 queue: &'static str,
49 },
50
51 #[error("operation timeout after {ms}ms")]
53 Timeout {
54 ms: u64,
56 },
57
58 #[error(transparent)]
60 External(#[from] anyhow::Error),
61}
62
63pub type Result<T, E = Error> = std::result::Result<T, E>;
65
66impl From<crate::pipeline::PipelineError> for Error {
67 fn from(err: crate::pipeline::PipelineError) -> Self {
68 match err {
69 crate::pipeline::PipelineError::Backpressure { queue } => Self::Backpressure { queue },
70 crate::pipeline::PipelineError::WorkerShutdown { queue } => {
71 Self::WorkerShutdown { queue }
72 }
73 }
74 }
75}
76
77impl Error {
78 #[must_use]
80 pub fn kind(&self) -> &'static str {
81 match self {
82 Self::Storage(_) => "storage",
83 Self::Embeddings(_) => "embeddings",
84 Self::Domain(_) => "domain",
85 Self::SessionNotFound(_) => "session_not_found",
86 Self::CircuitBreaker(_) => "circuit_breaker",
87 Self::Backpressure { .. } => "backpressure",
88 Self::WorkerShutdown { .. } => "worker_shutdown",
89 Self::Timeout { .. } => "timeout",
90 Self::External(_) => "external",
91 }
92 }
93}