use dig_store::CapsuleIdentity;
use std::path::PathBuf;
#[derive(Debug, thiserror::Error)]
pub enum CacheError {
#[error("i/o error at {path}: {source}")]
Io {
path: PathBuf,
#[source]
source: std::io::Error,
},
#[error("capsule {id:?} is {size} bytes, larger than the cache capacity of {capacity} bytes")]
EntryTooLarge {
id: Box<CapsuleIdentity>,
size: u64,
capacity: u64,
},
#[error("capsule bytes declare {recovered:?} but the caller claimed {claimed:?}")]
IdentityMismatch {
claimed: Box<CapsuleIdentity>,
recovered: Box<CapsuleIdentity>,
},
#[error("cached capsule at {path} is corrupt: {reason}")]
CorruptEntry {
path: PathBuf,
reason: String,
},
#[error("cache root {root} is not writable: {source}")]
RootNotWritable {
root: PathBuf,
#[source]
source: std::io::Error,
},
}
impl CacheError {
pub(crate) fn io(path: impl Into<PathBuf>, source: std::io::Error) -> Self {
Self::Io {
path: path.into(),
source,
}
}
}