aboutsummaryrefslogtreecommitdiff
path: root/crates/texm/src/error.rs
blob: a5dda77afe83e3f74fd8ffee206f92f0dcdd5d65 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use core::fmt;

#[derive(Debug)]
pub enum Error {
    HeaderTooSmall {
        size: usize,
    },
    InvalidMagic {
        got: u32,
    },
    InvalidDimensions {
        width: u32,
        height: u32,
    },
    InvalidMipCount {
        mip_count: u32,
    },
    UnknownFormat {
        format: u32,
    },
    IntegerOverflow,
    CoreDataOutOfBounds {
        expected_end: usize,
        actual_size: usize,
    },
    InvalidPageMagic,
    InvalidPageSize {
        expected: usize,
        actual: usize,
    },
}

impl fmt::Display for Error {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::HeaderTooSmall { size } => {
                write!(f, "Texm payload too small for header: {size}")
            }
            Self::InvalidMagic { got } => write!(f, "invalid Texm magic: 0x{got:08X}"),
            Self::InvalidDimensions { width, height } => {
                write!(f, "invalid Texm dimensions: {width}x{height}")
            }
            Self::InvalidMipCount { mip_count } => write!(f, "invalid Texm mip_count={mip_count}"),
            Self::UnknownFormat { format } => write!(f, "unknown Texm format={format}"),
            Self::IntegerOverflow => write!(f, "integer overflow"),
            Self::CoreDataOutOfBounds {
                expected_end,
                actual_size,
            } => write!(
                f,
                "Texm core data out of bounds: expected_end={expected_end}, actual_size={actual_size}"
            ),
            Self::InvalidPageMagic => write!(f, "Texm tail exists but Page magic is missing"),
            Self::InvalidPageSize { expected, actual } => {
                write!(f, "invalid Page chunk size: expected={expected}, actual={actual}")
            }
        }
    }
}

impl std::error::Error for Error {}