tidaldb/tidal/src/storage/error.rs
jx12n 9728194f16 fix: M0-M10 code-review pass2 remediation — all 91 findings
Resolves every finding in docs/reviews/M0-M10-code-review-2026-06-08-pass2.md
across the engine, network, server, and CLI crates: session restore,
replication/CRDT, WAL format and recovery, storage indexes, query/ranking
executors, cohort/community governance, and scatter-gather routing.

Adds regression tests:
- review_pass2_creator_search_filter
- review_pass2_d_replication
- review_pass2_query_for_session
- review_pass2_storage_indexes_bitmap_cache
- review_pass2_zone_a_sessions

Verified: cargo clippy -D warnings and full test suite green across all crates.
2026-06-09 12:21:00 -06:00

69 lines
1.9 KiB
Rust

/// Storage engine error types.
///
/// Replaces the stub `StorageError { message }` from Phase 1.1.
/// All storage backends surface errors through this enum.
#[derive(Debug, thiserror::Error)]
pub enum StorageError {
/// I/O error from the underlying filesystem or storage engine.
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
/// Data corruption detected (checksum mismatch, invalid key encoding, etc.).
#[error("data corruption: {message}")]
Corruption { message: String },
/// The storage engine has been closed and cannot service requests.
#[error("storage closed")]
Closed,
}
#[cfg(test)]
#[allow(clippy::unwrap_used)]
mod tests {
use super::*;
#[test]
fn display_io() {
let e = StorageError::Io(std::io::Error::new(
std::io::ErrorKind::NotFound,
"file not found",
));
assert!(e.to_string().contains("I/O error"));
assert!(e.to_string().contains("file not found"));
}
#[test]
fn display_corruption() {
let e = StorageError::Corruption {
message: "bad checksum".into(),
};
assert_eq!(e.to_string(), "data corruption: bad checksum");
}
#[test]
fn display_closed() {
assert_eq!(StorageError::Closed.to_string(), "storage closed");
}
#[test]
fn from_io_error() {
let io_err = std::io::Error::other("disk full");
let storage_err: StorageError = io_err.into();
assert!(matches!(storage_err, StorageError::Io(_)));
}
#[test]
fn source_io() {
use std::error::Error;
let e = StorageError::Io(std::io::Error::other("test"));
assert!(e.source().is_some());
}
#[test]
fn source_corruption_is_none() {
use std::error::Error;
let e = StorageError::Corruption {
message: "test".into(),
};
assert!(e.source().is_none());
}
}