Skip to main content

khata_rs/
error.rs

1//! Error types for Queue operations.
2
3use std::path::PathBuf;
4use thiserror::Error;
5
6pub type Result<T> = std::result::Result<T, Error>;
7
8/// Errors that can occur during Queue operations.
9#[derive(Debug, Error)]
10pub enum Error {
11    /// An I/O error occurred.
12    #[error("I/O error: {0}")]
13    Io(#[from] std::io::Error),
14
15    /// The queue has been closed.
16    #[error("queue is closed")]
17    QueueClosed,
18
19    /// An invalid index was specified.
20    #[error("invalid index: {0:#x}")]
21    InvalidIndex(u64),
22
23    /// The specified cycle was not found.
24    #[error("cycle not found: {0}")]
25    CycleNotFound(i32),
26
27    /// A store file is missing.
28    #[error("store file missing: {}", .0.display())]
29    StoreFileMissing(PathBuf),
30
31    /// Data corruption was detected.
32    #[error("corrupted data at position {0}")]
33    CorruptedData(u64),
34
35    /// Attempted to write to a read-only queue.
36    #[error("queue is read-only")]
37    ReadOnly,
38
39    /// The queue directory could not be created.
40    #[error("failed to create queue directory: {}", .0.display())]
41    DirectoryCreationFailed(PathBuf),
42
43    /// The write position exceeded the file capacity.
44    #[error("write position {position} exceeds capacity {capacity}")]
45    CapacityExceeded { position: u64, capacity: u64 },
46
47    /// Failed to acquire a lock.
48    #[error("failed to acquire lock: {0}")]
49    LockFailed(String),
50
51    /// The header is invalid or corrupted.
52    #[error("invalid header at position {0}")]
53    InvalidHeader(u64),
54}