use std::io;
use kimberlite_crypto::ChainHash;
use kimberlite_types::Offset;
#[derive(thiserror::Error, Debug)]
pub enum StorageError {
#[error("error writing batch payload")]
WriteError,
#[error("filesystem error: {0}")]
Io(#[from] io::Error),
#[error("unexpected end of file")]
UnexpectedEof,
#[error("corrupted record: CRC mismatch")]
CorruptedRecord,
#[error("torn write detected: {reason}")]
TornWrite { reason: String },
#[error("invalid record kind byte {byte:#04x} at offset {offset}")]
InvalidRecordKind { byte: u8, offset: Offset },
#[error(
"hash chain verification failed at offset {offset}: expected {expected:?}, found {actual:?}"
)]
ChainVerificationFailed {
offset: Offset,
expected: Option<ChainHash>,
actual: Option<ChainHash>,
},
#[error("invalid checkpoint payload at offset {offset}: {reason}")]
InvalidCheckpointPayload { offset: Offset, reason: String },
#[error("invalid index magic bytes")]
InvalidIndexMagic,
#[error("unsupported index version: {0}")]
UnsupportedIndexVersion(u8),
#[error("index checksum mismatch: expected {expected:#010x}, got {actual:#010x}")]
IndexChecksumMismatch { expected: u32, actual: u32 },
#[error("truncated index file: expected {expected} bytes, got {actual}")]
IndexTruncated { expected: usize, actual: usize },
#[error("{codec} compression failed: {reason}")]
CompressionFailed { codec: &'static str, reason: String },
#[error("{codec} decompression failed: {reason}")]
DecompressionFailed { codec: &'static str, reason: String },
#[error("invalid compression kind byte {byte:#04x} at offset {offset}")]
InvalidCompressionKind { byte: u8, offset: Offset },
}