Files
nx9-wg/crates/nx9-wg-db/src/error.rs
T
thakaresandCopilot 2ac6c81dfe cli: avoid data-dir initialization for version; create db parent dirs; redact generated passwords in CLI output
- 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>
2026-08-16 16:26:24 +05:30

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())
}
}