use thiserror::Error;
#[derive(Debug, Error)]
pub enum LoadError {
#[error("{0}")]
Parsing(String),
#[error("File system error with file {0}, due: {1}")]
FileSystem(std::path::PathBuf, std::io::Error),
#[error("Cannot derive mipmap name for {0}")]
InvalidFilename(std::path::PathBuf),
}
#[derive(Debug, Error)]
pub enum Error {
#[error("Unexpected magic value {0}. The file format is not BLP or not supported.")]
WrongMagic(String),
#[error("Failed to extract external mipmap number {0} with error {1}")]
ExternalMipmap(usize, Box<dyn std::error::Error>),
#[error("There is no body of image for BLP0 mipmap number {0}")]
MissingImage(usize),
#[error("Part of image exceeds bounds of file at offset {offset} with size {size}")]
OutOfBounds {
offset: usize,
size: usize,
},
#[error("BLP2 doesn't support external mipmaps")]
Blp2NoExternalMips,
#[error("Library doesn't support compression tag: {0}")]
Blp2UnknownCompression(u8),
#[error("Library doesn't support alpha type: {0}")]
Blp2UnknownAlphaType(u8),
#[error("Unknown alpha type value: {0}")]
UnknownAlphaType(u8),
#[error("Impossible branch, JPEG compression but direct content type")]
Blp2UnexpectedJpegCompression,
#[error("Unexpected end of file")]
UnexpectedEof,
#[error("Context: {0}. Error: {1}")]
Context(String, Box<Self>),
}
impl Error {
pub fn with_context(self, context: &str) -> Self {
Error::Context(context.to_owned(), Box::new(self))
}
}