use std::io;
#[derive(Debug, thiserror::Error)]
pub enum CompressError {
#[error("invalid compression level: {0}")]
InvalidLevel(i32),
#[error("io error while compressing: {0}")]
Io(#[from] io::Error),
#[error("zrip compression error: {0}")]
Zrip(#[from] zrip::CompressError),
}
#[derive(Debug, thiserror::Error)]
pub enum DecompressError {
#[error("truncated compressed stream: {0}")]
Truncated(io::Error),
#[error("io error while decompressing: {0}")]
Io(#[from] io::Error),
#[error("frame output exceeds safety limit of {limit} bytes")]
TooLarge {
limit: usize,
},
}
#[derive(Debug, thiserror::Error)]
pub enum StorageError {
#[error("path not found: {0}")]
NotFound(String),
#[error("path already exists: {0}")]
AlreadyExists(String),
#[error("file too large: {0}")]
TooLarge(u64),
#[error("write failed at offset {offset}: {source}")]
WriteFailed {
offset: u64,
#[source]
source: io::Error,
},
#[error("operation not supported: {0}")]
Unsupported(&'static str),
#[error("storage error: {0}")]
Other(#[from] io::Error),
}
impl StorageError {
pub fn write_failed(offset: u64, source: io::Error) -> Self {
StorageError::WriteFailed { offset, source }
}
}