faf_rust_sdk/binary/
error.rs1use thiserror::Error;
6
7#[derive(Error, Debug)]
9pub enum FafbError {
10 #[error("Invalid magic number: expected FAFB (0x46414642), got {0:#010x}")]
12 InvalidMagic(u32),
13
14 #[error("Incompatible version: expected major version {expected}, got {actual}")]
16 IncompatibleVersion { expected: u8, actual: u8 },
17
18 #[error("Checksum mismatch: expected {expected:#010x}, got {actual:#010x}")]
20 ChecksumMismatch { expected: u32, actual: u32 },
21
22 #[error("File too small: expected at least {expected} bytes, got {actual}")]
24 FileTooSmall { expected: usize, actual: usize },
25
26 #[error("Invalid section table offset: {offset} exceeds file size {file_size}")]
28 InvalidSectionTableOffset { offset: u32, file_size: u32 },
29
30 #[error("Section count {count} exceeds maximum {max}")]
32 TooManySections { count: u16, max: u16 },
33
34 #[error("IO error: {0}")]
36 Io(#[from] std::io::Error),
37
38 #[error("Size mismatch: header says {header_size} bytes, actual {actual_size}")]
40 SizeMismatch {
41 header_size: u32,
42 actual_size: usize,
43 },
44
45 #[error("String table index {index} out of bounds (table has {count} entries)")]
47 StringTableIndexOutOfBounds { index: u8, count: u16 },
48
49 #[error("String table entry too long: {length} bytes exceeds maximum {max}")]
51 StringTableEntryTooLong { length: usize, max: usize },
52
53 #[error("String table full: maximum {max} entries")]
55 StringTableFull { max: usize },
56
57 #[error("Missing string table section (required for FAFb v2)")]
59 MissingStringTable,
60
61 #[error("Invalid UTF-8 in string table: {0}")]
63 InvalidUtf8(String),
64}
65
66pub type FafbResult<T> = Result<T, FafbError>;