Skip to main content

faf_fafb/
error.rs

1//! FAFB Error Types
2//!
3//! Error handling for binary format operations.
4
5use thiserror::Error;
6
7/// Errors that can occur when working with .fafb files
8#[derive(Error, Debug)]
9pub enum FafbError {
10    /// Invalid magic number - not a FAFB file
11    #[error("Invalid magic number: expected FAFB (0x46414642), got {0:#010x}")]
12    InvalidMagic(u32),
13
14    /// Incompatible major version
15    #[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    /// Checksum mismatch - file may be corrupted
21    #[error("Checksum mismatch: expected {expected:#010x}, got {actual:#010x}")]
22    ChecksumMismatch { expected: u32, actual: u32 },
23
24    /// File too small to contain valid header
25    #[error("File too small: expected at least {expected} bytes, got {actual}")]
26    FileTooSmall { expected: usize, actual: usize },
27
28    /// Section table offset points outside file bounds
29    #[error("Invalid section table offset: {offset} exceeds file size {file_size}")]
30    InvalidSectionTableOffset { offset: u32, file_size: u32 },
31
32    /// Section count exceeds maximum allowed
33    #[error("Section count {count} exceeds maximum {max}")]
34    TooManySections { count: u16, max: u16 },
35
36    /// IO error during read/write
37    #[error("IO error: {0}")]
38    Io(#[from] std::io::Error),
39
40    /// Total size in header doesn't match actual data
41    #[error("Size mismatch: header says {header_size} bytes, actual {actual_size}")]
42    SizeMismatch {
43        header_size: u32,
44        actual_size: usize,
45    },
46
47    /// String table index out of bounds
48    #[error("String table index {index} out of bounds (table has {count} entries)")]
49    StringTableIndexOutOfBounds { index: u8, count: u16 },
50
51    /// String table entry exceeds maximum length
52    #[error("String table entry too long: {length} bytes exceeds maximum {max}")]
53    StringTableEntryTooLong { length: usize, max: usize },
54
55    /// String table is full (256 entries max)
56    #[error("String table full: maximum {max} entries")]
57    StringTableFull { max: usize },
58
59    /// Missing string table section in v2 file
60    #[error("Missing string table section (required for FAFb v2)")]
61    MissingStringTable,
62
63    /// Invalid UTF-8 in string table
64    #[error("Invalid UTF-8 in string table: {0}")]
65    InvalidUtf8(String),
66}
67
68/// Result type for FAFB operations
69pub type FafbResult<T> = Result<T, FafbError>;