use butck_policies::error::ChunkFailed; use crate::chunker::context::ButckContext; #[derive(Debug)] pub struct ButckRWError { kind: ButckRWErrorKind, ctx: ButckContext, } #[derive(thiserror::Error, Debug)] pub enum ButckRWErrorKind { #[error("No butck storage found")] NoButckStorageFound, #[error("Chunking policy not specified")] ChunkingPolicyNotSpecified, #[error("Cannot enable both MemmapRead and StreamRead")] ReadingMethodAmbiguous, #[error("Multiple input files specified but only one output file allowed")] OutputCountMismatch, #[error("Invalid bidx file format")] InvalidBidxFormat, #[error("Chunk not found in storage: {0}")] ChunkNotFound(String), #[error("Failed to rebuild file: {0}")] RebuildFailed(String), #[error("Chunking failed: {0}")] ChunkFailed(#[from] ChunkFailed), #[error("IO error: {0}")] IOError(#[from] std::io::Error), } impl std::fmt::Display for ButckRWError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{:?}", self.kind) } } impl ButckRWError { pub fn ctx(&self) -> &ButckContext { &self.ctx } pub fn kind(&self) -> &ButckRWErrorKind { &self.kind } } impl ButckRWErrorKind { pub fn pack(self, ctx: ButckContext) -> ButckRWError { ButckRWError { kind: self, ctx } } }