use std::path::{Path, PathBuf};
use thiserror::Error;
#[derive(Debug, Error)]
pub enum FormatError {
#[error("{}: {source}", path.display())]
Io {
path: PathBuf,
#[source]
source: std::io::Error,
},
#[error("{}: invalid JSON: {source}", path.display())]
Json {
path: PathBuf,
#[source]
source: serde_json::Error,
},
#[error("serializing {what}: {source}")]
Serialize {
what: &'static str,
#[source]
source: serde_json::Error,
},
#[error("{}: larger than the {max}-byte cap for format metadata", path.display())]
FileTooLarge {
path: PathBuf,
max: u64,
},
#[error("unsupported rvmp_version {found} (this build supports {supported})")]
UnsupportedVersion {
found: u32,
supported: u32,
},
#[error("unknown quant scheme {scheme:?} (known: {known:?})")]
UnknownQuantScheme {
scheme: String,
known: &'static [&'static str],
},
#[error("invalid architecture: {0}")]
InvalidArch(String),
#[error("invalid manifest: {0}")]
InvalidManifest(String),
#[error("invalid experts layout: {0}")]
InvalidLayout(String),
#[error("{what} {name:?}: {value} is not a multiple of {align}")]
Misaligned {
what: &'static str,
name: String,
value: u64,
align: u64,
},
#[error("no manifest files entry for {0:?}")]
MissingFileEntry(String),
#[error("unsafe file name {0:?}: must be relative with no `..` components")]
UnsafeFileName(String),
#[error("{name:?}: manifest says {expected} bytes, found {actual}")]
SizeMismatch {
name: String,
expected: u64,
actual: u64,
},
#[error("{name:?}: sha256 mismatch (manifest {expected}, computed {actual})")]
HashMismatch {
name: String,
expected: String,
actual: String,
},
#[error("install target {} already exists", .0.display())]
AlreadyExists(PathBuf),
}
impl FormatError {
pub(crate) fn io(path: &Path, source: std::io::Error) -> Self {
Self::Io {
path: path.to_path_buf(),
source,
}
}
}