//! Database error types. use thiserror::Error; /// Result type for database operations. pub type Result = std::result::Result; /// Database-specific errors. #[derive(Debug, Error)] pub enum DbError { /// Entity was not found. #[error("entity not found: {0}")] NotFound(String), /// Unique or foreign key constraint violation. #[error("constraint violation: {0}")] ConstraintViolation(String), /// Conflict, e.g. entity already exists. #[error("conflict: {0}")] Conflict(String), /// Validation error when converting from raw database values. #[error("validation error: {0}")] Validation(String), /// SQLx database error. #[error("database error: {0}")] Sqlx(#[from] sqlx::Error), /// Migration failure. #[error("migration error: {0}")] Migration(String), /// Internal or unexpected error. #[error("internal database error: {0}")] Internal(String), } impl From for DbError { fn from(err: nx9_wg_core::error::Nx9Error) -> Self { Self::Validation(err.to_string()) } }