- Prevent 'nx9-wg version' from creating data directories by avoiding database initialization. - Create parent directories when an explicit --database path is provided. - Redact printed generated administrator passwords; announce file path or redact instead. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
45 lines
1.1 KiB
Rust
45 lines
1.1 KiB
Rust
//! Database error types.
|
|
|
|
use thiserror::Error;
|
|
|
|
/// Result type for database operations.
|
|
pub type Result<T> = std::result::Result<T, DbError>;
|
|
|
|
/// 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<nx9_wg_core::error::Nx9Error> for DbError {
|
|
fn from(err: nx9_wg_core::error::Nx9Error) -> Self {
|
|
Self::Validation(err.to_string())
|
|
}
|
|
}
|