1use 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(
16 "Incompatible version: expected major version {expected}, got {actual}. FAFb v1 is pre-release history — re-compile from the .faf source"
17 )]
18 IncompatibleVersion { expected: u8, actual: u8 },
19
20 #[error("Checksum mismatch: expected {expected:#010x}, got {actual:#010x}")]
22 ChecksumMismatch { expected: u32, actual: u32 },
23
24 #[error("File too small: expected at least {expected} bytes, got {actual}")]
26 FileTooSmall { expected: usize, actual: usize },
27
28 #[error("Invalid section table offset: {offset} exceeds file size {file_size}")]
30 InvalidSectionTableOffset { offset: u32, file_size: u32 },
31
32 #[error("Section count {count} exceeds maximum {max}")]
34 TooManySections { count: u16, max: u16 },
35
36 #[error("IO error: {0}")]
38 Io(#[from] std::io::Error),
39
40 #[error("Size mismatch: header says {header_size} bytes, actual {actual_size}")]
42 SizeMismatch {
43 header_size: u32,
44 actual_size: usize,
45 },
46
47 #[error("String table index {index} out of bounds (table has {count} entries)")]
49 StringTableIndexOutOfBounds { index: u8, count: u16 },
50
51 #[error("String table entry too long: {length} bytes exceeds maximum {max}")]
53 StringTableEntryTooLong { length: usize, max: usize },
54
55 #[error("String table full: maximum {max} entries")]
57 StringTableFull { max: usize },
58
59 #[error("Missing string table section (required for FAFb v2)")]
61 MissingStringTable,
62
63 #[error("Invalid UTF-8 in string table: {0}")]
65 InvalidUtf8(String),
66}
67
68pub type FafbResult<T> = Result<T, FafbError>;