diff options
Diffstat (limited to 'src/chunker/rw/error.rs')
| -rw-r--r-- | src/chunker/rw/error.rs | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/chunker/rw/error.rs b/src/chunker/rw/error.rs new file mode 100644 index 0000000..7f263a5 --- /dev/null +++ b/src/chunker/rw/error.rs @@ -0,0 +1,61 @@ +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 } + } +} |
