use std::io;
use thiserror::Error as ThisError;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(ThisError, Debug)]
#[non_exhaustive]
pub enum ParseError {
#[error("value {value} is outside {bound}")]
OutOfBounds { value: String, bound: String },
#[error("unknown format: {0}")]
UnknownFormat(String),
#[error("unknown filetype: {0}")]
UnknownFileType(String),
#[error("expected a {expected} file, got {got}")]
WrongFormat { expected: &'static str, got: String },
#[error("{0}")]
AssertFail(String),
#[error(
"{format}: schema version {version} is not supported (known: {supported:?}); \
refusing to decode rather than risk misreading fields"
)]
UnsupportedVersion {
format: &'static str,
version: u32,
supported: &'static [u32],
},
#[error(
"{format}: the body is {got} bytes where the format holds {expected}; \
refusing rather than misread fields"
)]
WrongBodyLength {
format: String,
got: u64,
expected: u64,
},
}
impl From<std::convert::Infallible> for ParseError {
fn from(never: std::convert::Infallible) -> Self {
match never {}
}
}
#[derive(ThisError, Debug)]
#[non_exhaustive]
pub enum Error {
#[error(transparent)]
Io(#[from] io::Error),
#[error(transparent)]
Parse(#[from] ParseError),
#[cfg(feature = "bundle")]
#[error(transparent)]
Zip(#[from] zip::result::ZipError),
}