epoch_forge/bin_efo/src/error.rs

50 lines
1.5 KiB
Rust

//! General error type that the CLI propagates.
//!
//! `AppError` aggregates all error kinds that may surface during a command
//! execution: parsing, I/O, epoch logic, storage, and a catch-all.
#![warn(missing_docs, clippy::missing_docs_in_private_items)]
use lib_efo::{
error::{EpochError, StorageError},
migration::MigrationError,
transaction::TransactionError,
};
use miette::Diagnostic;
use thiserror::Error;
/// All errors that can bubble up to the CLI.
#[derive(Debug, Error, Diagnostic)]
pub enum AppError {
/// Generic “invalid command / missing flag” - emitted by clap.
#[error("Command-line error: {0}")]
// #[diagnostic(transparent)]
Clap(#[from] clap::Error),
/// Errors that happen when reading / writing the JSON file.
#[error("I/O error: {0}")]
// #[diagnostic(transparent)]
Io(#[from] std::io::Error),
/// Domain-specific problems (see `EpochError`).
#[error("Epoch error:")]
#[diagnostic(transparent)]
Epoch(#[from] EpochError),
/// Storage-layer (e.g. DB) errors.
#[error("Storage error: {0}")]
// #[diagnostic(transparent)]
Storage(#[from] StorageError),
/// Repository-format migration failed safely.
#[error("Migration stopped: {0}")]
Migration(#[from] MigrationError),
/// Exclusive locking or interrupted-write recovery failed safely.
#[error("Repository safety check stopped: {0}")]
Transaction(#[from] TransactionError),
// /// Anything else we didn't anticipate.
// #[error("Unknown error: {0}")]
// Other(String),
}