1use thiserror::Error;
2
3#[derive(Debug, Error)]
5pub enum LoadError {
6 #[error("{0}")]
8 Parsing(String),
9 #[error("File system error with file {0}, due: {1}")]
11 FileSystem(std::path::PathBuf, std::io::Error),
12 #[error("Cannot derive mipmap name for {0}")]
14 InvalidFilename(std::path::PathBuf),
15}
16
17#[derive(Debug, Error)]
19pub enum Error {
20 #[error("Unexpected magic value {0}. The file format is not BLP or not supported.")]
22 WrongMagic(String),
23 #[error("Failed to extract external mipmap number {0} with error {1}")]
25 ExternalMipmap(usize, Box<dyn std::error::Error>),
26 #[error("There is no body of image for BLP0 mipmap number {0}")]
28 MissingImage(usize),
29 #[error("Part of image exceeds bounds of file at offset {offset} with size {size}")]
31 OutOfBounds {
32 offset: usize,
34 size: usize,
36 },
37 #[error("BLP2 doesn't support external mipmaps")]
39 Blp2NoExternalMips,
40 #[error("Library doesn't support compression tag: {0}")]
42 Blp2UnknownCompression(u8),
43 #[error("Library doesn't support alpha type: {0}")]
45 Blp2UnknownAlphaType(u8),
46 #[error("Unknown alpha type value: {0}")]
48 UnknownAlphaType(u8),
49 #[error("Impossible branch, JPEG compression but direct content type")]
51 Blp2UnexpectedJpegCompression,
52 #[error("Unexpected end of file")]
54 UnexpectedEof,
55 #[error("Context: {0}. Error: {1}")]
57 Context(String, Box<Self>),
58}
59
60impl Error {
61 pub fn with_context(self, context: &str) -> Self {
63 Error::Context(context.to_owned(), Box::new(self))
64 }
65}