//! Domain error types for the CMS module. //! //! Typed error enums for repository and service operations. //! //! # Components //! //! - [`RepositoryError`] — persistence-layer errors (not found, conflict, I/O) //! - [`ServiceError`] — use-case / orchestration errors (invalid input, generic) use std::fmt; use crate::error::DomainError; /// Shared repository error type for CMS persistence operations. pub type RepositoryError = DomainError; /// Errors from service / use-case operations in the CMS domain. #[derive(Debug)] pub enum ServiceError { /// A repository operation failed. Repository(DomainError), /// The provided input is invalid. InvalidInput(String), /// A generic error with a message. Other(String), } impl From for ServiceError { fn from(err: DomainError) -> Self { ServiceError::Repository(err) } } impl fmt::Display for ServiceError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { ServiceError::Repository(err) => write!(f, "repository error: {err}"), ServiceError::InvalidInput(msg) => write!(f, "invalid input: {msg}"), ServiceError::Other(msg) => write!(f, "{msg}"), } } } impl std::error::Error for ServiceError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { match self { ServiceError::Repository(err) => Some(err), _ => None, } } }