Skip to main content

uls_db/
error.rs

1//! Database error types.
2
3use std::path::PathBuf;
4use thiserror::Error;
5
6/// Errors that can occur during database operations.
7#[derive(Error, Debug)]
8pub enum DbError {
9    /// SQLite error.
10    #[error("SQLite error: {0}")]
11    Sqlite(#[from] rusqlite::Error),
12
13    /// Connection pool error.
14    #[error("connection pool error: {0}")]
15    Pool(#[from] r2d2::Error),
16
17    /// I/O error.
18    #[error("I/O error: {0}")]
19    Io(#[from] std::io::Error),
20
21    /// Record not found.
22    #[error("record not found: {0}")]
23    NotFound(String),
24
25    /// Database not initialized.
26    #[error("database not initialized - run 'uls update' first")]
27    NotInitialized,
28
29    /// Schema version mismatch.
30    #[error("schema version mismatch: expected {expected}, found {found}")]
31    SchemaVersionMismatch { expected: i32, found: i32 },
32
33    /// Database file does not exist.
34    #[error("database file not found: {0}")]
35    FileNotFound(PathBuf),
36
37    /// Invalid data.
38    #[error("invalid data: {0}")]
39    InvalidData(String),
40
41    /// Transaction error.
42    #[error("transaction error: {0}")]
43    Transaction(String),
44
45    /// Parser error.
46    #[error("parser error: {0}")]
47    Parser(#[from] uls_parser::ParseError),
48
49    /// ZIP archive error.
50    #[error("zip error: {0}")]
51    Zip(#[from] uls_parser::archive::ZipError),
52}
53
54/// Result type for database operations.
55pub type Result<T> = std::result::Result<T, DbError>;