flowdb/error.rs
1/// Error type for all FlowDB operations.
2///
3/// Wraps I/O errors, corruption, configuration validation, JSON errors, and
4/// JsonDB-layer errors into a single `FlowError` enum.
5#[derive(Debug, thiserror::Error)]
6pub enum FlowError {
7 /// Wraps [`std::io::Error`] from file system operations.
8 #[error("IO error: {0}")]
9 Io(#[from] std::io::Error),
10 /// Data corruption detected in an SSTable or WAL segment.
11 #[error("Corruption in {file}: {msg}")]
12 Corruption { file: String, msg: String },
13 /// Operation attempted on a closed engine.
14 #[error("Engine is closed")]
15 Closed,
16 /// Write stalled because the write buffer is full (backpressure).
17 #[error("Write buffer full")]
18 WriteBufferFull,
19 /// Invalid configuration value (caught by [`Config::validate`]).
20 #[error("Config error: {0}")]
21 Config(String),
22 /// SSTable file not found by ID.
23 #[error("SSTable not found: {0}")]
24 SstNotFound(u32),
25 /// Block index entry refers to a non-existent block.
26 #[error("Block not found: sst={sst_id}, block={block_idx}")]
27 BlockNotFound { sst_id: u32, block_idx: u32 },
28 /// SSTable header magic number mismatch (wrong file format).
29 #[error("Invalid magic: expected {expected:#x}, got {actual:#x}")]
30 InvalidMagic { expected: u32, actual: u32 },
31 /// JSON serialization / deserialization error.
32 #[error("JSON error: {0}")]
33 Json(#[from] serde_json::Error),
34 /// JsonDB-level error (store not found, unique constraint violation, etc.).
35 #[error("JsonDB: {0}")]
36 JsonDb(String),
37 /// Catch-all error for miscellaneous failures.
38 #[error("{0}")]
39 Other(String),
40}
41
42/// Convenience type alias for `Result<T, FlowError>`.
43pub type Result<T> = std::result::Result<T, FlowError>;