Skip to main content

source_vtf/
error.rs

1use std::io;
2use std::path::PathBuf;
3
4use thiserror::Error;
5
6use crate::ResourceTag;
7
8pub type Result<T> = std::result::Result<T, Error>;
9
10#[derive(Debug, Error)]
11pub enum Error {
12    #[error("I/O error for `{path}`: {source}")]
13    Io {
14        path: PathBuf,
15        #[source]
16        source: io::Error,
17    },
18
19    #[error("invalid VTF signature 0x{0:08x}")]
20    InvalidSignature(u32),
21
22    #[error("unsupported VTF version {major}.{minor}")]
23    UnsupportedVersion { major: u32, minor: u32 },
24
25    #[error("{field} {id} is a pre-7.5 depth-buffer format, which has no image data to read")]
26    UnsupportedFormat { field: &'static str, id: i32 },
27
28    #[error("VTF {context} range {offset}..{end} is outside 0..{size}")]
29    OutOfBounds {
30        context: &'static str,
31        offset: usize,
32        end: usize,
33        size: usize,
34    },
35
36    #[error("invalid {field} value {value}: {reason}")]
37    InvalidField {
38        field: &'static str,
39        value: i64,
40        reason: &'static str,
41    },
42
43    /// Not in the resource dictionary, or listed inline without a data chunk
44    #[error("VTF has no data for resource 0x{:06x}", .0.0)]
45    MissingResource(ResourceTag),
46
47    #[error("{context} index {index} is out of range for {count} values")]
48    InvalidIndex {
49        context: &'static str,
50        index: u32,
51        count: u32,
52    },
53}