use std::io;
use std::path::PathBuf;
use crate::store::{CompressionFormat, CACHE_VERSION};
#[derive(Debug, thiserror::Error)]
#[expect(missing_docs)]
pub enum Error {
#[error("{}: {:?}", inner, path)]
IO { inner: io::Error, path: Option<PathBuf> },
#[error("Failed to parse SPDX license list data file '{}' ({})", path.to_string_lossy(), inner)]
SpdxData { inner: serde_json::Error, path: PathBuf },
#[error(
"Unexpected cache version (expected '{}-????', found '{}'",
String::from_utf8_lossy(CACHE_VERSION),
String::from_utf8_lossy(header)
)]
CacheVersion { header: Vec<u8> },
#[error("Cache deserialization failure: {}", inner)]
CacheParse {
#[from]
inner: rmp_serde::decode::Error,
},
#[error("Cache serialization failure: {}", inner)]
CacheWrite {
#[from]
inner: rmp_serde::encode::Error,
},
#[error("Unsupported compression format (scallion was not compiled with {} support)", cf)]
CacheFormat { cf: CompressionFormat },
}
impl Error {
#[must_use]
pub(crate) const fn io(inner: io::Error, path: Option<PathBuf>) -> Self {
Error::IO { inner, path }
}
#[must_use]
pub(crate) const fn spdx(inner: serde_json::Error, path: PathBuf) -> Self {
Error::SpdxData { inner, path }
}
#[must_use]
pub(crate) const fn cache_version(header: Vec<u8>) -> Self {
Error::CacheVersion { header }
}
#[must_use]
#[cfg(not(all(feature = "zstd", feature = "gzip")))]
pub(crate) const fn cache_format(cf: CompressionFormat) -> Self {
Error::CacheFormat { cf }
}
}