#![deny(missing_docs)]
use std::io;
use std::num::ParseIntError;
use thiserror::Error;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Error, Debug)]
#[non_exhaustive]
pub enum Error {
#[error("IO error: {0}")]
Io(#[from] io::Error),
#[error("HTTP error: {0}")]
Http(#[from] reqwest::Error),
#[error("JSON error: {0}")]
Json(#[from] serde_json::Error),
#[error("ZIP error: {0}")]
Zip(#[from] zip::result::ZipError),
#[error("Header error: {0}")]
Header(#[from] reqwest::header::ToStrError),
#[error("Parse integer error: {0}")]
ParseInt(#[from] ParseIntError),
#[error("Missing header: {0}")]
MissingHeader(String),
#[error("Configuration error: {0}")]
Config(String),
#[error("manifest parse error: {0}")]
ManifestParse(String),
#[error("cache error: {0}")]
Cache(String),
#[error("{context} exceeds size limit of {limit} bytes")]
SizeLimitExceeded {
context: String,
limit: u64,
actual: Option<u64>,
},
#[error("incomplete download: expected {expected} bytes, received {actual}")]
IncompleteDownload {
expected: u64,
actual: u64,
},
#[error("unsafe name: {0}")]
UnsafeName(String),
#[error("unsupported cache format version {found} (expected {expected})")]
UnsupportedCacheVersion {
found: u32,
expected: u32,
},
#[error("Ecosystem error: {0}")]
Ecosystem(String),
#[error("Install error: {0}")]
Install(String),
#[error("Profile error: {0}")]
Profile(String),
#[error("Profile error: {0}")]
BadProfile(#[from] crate::profile::layout::BadProfile),
#[error("{failed} of {total} downloads failed; first error: {first}")]
Download {
failed: usize,
total: usize,
first: String,
},
#[error("invalid header: {0}")]
InvalidHeader(String),
#[error("Archive extraction limit exceeded: {0}")]
ExtractLimitExceeded(String),
#[error("CRC32 verification failed for {path}: expected {expected:08x}, got {actual:08x}")]
ChecksumMismatch {
path: String,
expected: u32,
actual: u32,
},
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn profile_error_displays_message() {
let err = Error::Profile("bad profile".to_string());
assert_eq!(err.to_string(), "Profile error: bad profile");
}
}