Skip to main content

tga_core/
errors.rs

1//! Error types for the `tga-core` crate.
2//!
3//! All library code in this crate returns [`Result<T>`], which is a type alias
4//! for `std::result::Result<T, TgaError>`. Errors implement `std::error::Error`
5//! via [`thiserror::Error`] so they integrate cleanly with both `anyhow`
6//! (in binary crates) and direct error matching.
7
8use thiserror::Error;
9
10/// Top-level error type for all `tga-core` operations.
11///
12/// Variants intentionally cover the surface area of I/O, serialization,
13/// database, migration, validation, and lookup failures. Add new variants
14/// rather than overloading [`TgaError::ValidationError`] for unrelated
15/// failure modes.
16#[derive(Debug, Error)]
17pub enum TgaError {
18    /// A `rusqlite`/SQLite error occurred.
19    #[error("database error: {0}")]
20    DbError(#[from] rusqlite::Error),
21
22    /// Configuration is structurally valid but semantically wrong
23    /// (e.g. missing required field, contradictory values).
24    #[error("configuration error: {0}")]
25    ConfigError(String),
26
27    /// An underlying `std::io` error (file not found, permission denied, etc.).
28    #[error("I/O error: {0}")]
29    IoError(#[from] std::io::Error),
30
31    /// YAML deserialization failure.
32    #[error("YAML deserialization error: {0}")]
33    SerdeYamlError(#[from] serde_yaml::Error),
34
35    /// JSON serialization/deserialization failure.
36    #[error("JSON serialization error: {0}")]
37    SerdeJsonError(#[from] serde_json::Error),
38
39    /// A validation rule on otherwise well-formed data failed.
40    #[error("validation error: {0}")]
41    ValidationError(String),
42
43    /// A requested entity was not found.
44    #[error("not found: {0}")]
45    NotFound(String),
46
47    /// A database migration failed to apply or could not be reconciled.
48    #[error("migration error: {0}")]
49    MigrationError(String),
50}
51
52/// Crate-wide `Result` alias.
53///
54/// Prefer `tga_core::Result<T>` over `std::result::Result<T, TgaError>`
55/// for brevity in signatures.
56pub type Result<T> = std::result::Result<T, TgaError>;