Files
zesdex/crates/zesdex-cms/src/domain/error.rs
T

42 lines
1.6 KiB
Rust
Raw Normal View History

//! Domain error types for the CMS crate.
//!
//! Typed error enums for repository and service operations.
//! The `RepositoryError` type is re-exported from `zesdex_utils::Error`,
//! which has all needed variants: `NotFound`, `Conflict`, `Io`, `Serde`,
//! `InvalidId`, `Other`, etc.
//!
//! `From` impls are generated by `thiserror::Error` derive macros.
//! Anyhow's blanket `From<E: StdError + Send + Sync + 'static>`
//! covers conversion to `anyhow::Error` for downstream code.
// ---------------------------------------------------------------------------
// RepositoryError (type alias)
// ---------------------------------------------------------------------------
/// Re-export shared repository error from `zesdex_utils`.
pub use zesdex_utils::Error as RepositoryError;
// `From<RepositoryError> for anyhow::Error` is covered by anyhow's blanket
// `impl<E: StdError + Send + Sync + 'static> From<E> for Error` — no
// explicit impl needed.
// ---------------------------------------------------------------------------
// ServiceError
// ---------------------------------------------------------------------------
/// Errors from service / use-case operations in the CMS domain.
#[derive(Debug, thiserror::Error)]
pub enum ServiceError {
/// A repository operation failed.
#[error("repository error: {0}")]
Repository(#[from] RepositoryError),
/// The provided input is invalid.
#[error("invalid input: {0}")]
InvalidInput(String),
/// A generic error with a message.
#[error("{0}")]
Other(String),
}
// `From<ServiceError> for anyhow::Error` is covered by anyhow's blanket impl.