use thiserror::Error;
use uuid::Uuid;
#[derive(Debug, Error)]
pub enum Error {
#[error(transparent)]
Storage(#[from] post_cortex_storage::error::Error),
#[error(transparent)]
Embeddings(#[from] post_cortex_embeddings::error::Error),
#[error(transparent)]
Domain(#[from] post_cortex_core::SystemError),
#[error("session not found: {0}")]
SessionNotFound(Uuid),
#[error("circuit breaker open: {0}")]
CircuitBreaker(String),
#[error("pipeline backpressure on {queue}")]
Backpressure {
queue: &'static str,
},
#[error("pipeline worker shut down: {queue}")]
WorkerShutdown {
queue: &'static str,
},
#[error("operation timeout after {ms}ms")]
Timeout {
ms: u64,
},
#[error(transparent)]
External(#[from] anyhow::Error),
}
pub type Result<T, E = Error> = std::result::Result<T, E>;
impl From<crate::pipeline::PipelineError> for Error {
fn from(err: crate::pipeline::PipelineError) -> Self {
match err {
crate::pipeline::PipelineError::Backpressure { queue } => Self::Backpressure { queue },
crate::pipeline::PipelineError::WorkerShutdown { queue } => {
Self::WorkerShutdown { queue }
}
}
}
}
impl Error {
#[must_use]
pub fn kind(&self) -> &'static str {
match self {
Self::Storage(_) => "storage",
Self::Embeddings(_) => "embeddings",
Self::Domain(_) => "domain",
Self::SessionNotFound(_) => "session_not_found",
Self::CircuitBreaker(_) => "circuit_breaker",
Self::Backpressure { .. } => "backpressure",
Self::WorkerShutdown { .. } => "worker_shutdown",
Self::Timeout { .. } => "timeout",
Self::External(_) => "external",
}
}
}