Skip to main content

faf_rust_sdk/binary/
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("Incompatible version: expected major version {expected}, got {actual}")]
16    IncompatibleVersion { expected: u8, actual: u8 },
17
18    /// Checksum mismatch - file may be corrupted
19    #[error("Checksum mismatch: expected {expected:#010x}, got {actual:#010x}")]
20    ChecksumMismatch { expected: u32, actual: u32 },
21
22    /// File too small to contain valid header
23    #[error("File too small: expected at least {expected} bytes, got {actual}")]
24    FileTooSmall { expected: usize, actual: usize },
25
26    /// Section table offset points outside file bounds
27    #[error("Invalid section table offset: {offset} exceeds file size {file_size}")]
28    InvalidSectionTableOffset { offset: u32, file_size: u32 },
29
30    /// Section count exceeds maximum allowed
31    #[error("Section count {count} exceeds maximum {max}")]
32    TooManySections { count: u16, max: u16 },
33
34    /// IO error during read/write
35    #[error("IO error: {0}")]
36    Io(#[from] std::io::Error),
37
38    /// Total size in header doesn't match actual data
39    #[error("Size mismatch: header says {header_size} bytes, actual {actual_size}")]
40    SizeMismatch {
41        header_size: u32,
42        actual_size: usize,
43    },
44
45    /// String table index out of bounds
46    #[error("String table index {index} out of bounds (table has {count} entries)")]
47    StringTableIndexOutOfBounds { index: u8, count: u16 },
48
49    /// String table entry exceeds maximum length
50    #[error("String table entry too long: {length} bytes exceeds maximum {max}")]
51    StringTableEntryTooLong { length: usize, max: usize },
52
53    /// String table is full (256 entries max)
54    #[error("String table full: maximum {max} entries")]
55    StringTableFull { max: usize },
56
57    /// Missing string table section in v2 file
58    #[error("Missing string table section (required for FAFb v2)")]
59    MissingStringTable,
60
61    /// Invalid UTF-8 in string table
62    #[error("Invalid UTF-8 in string table: {0}")]
63    InvalidUtf8(String),
64}
65
66/// Result type for FAFB operations
67pub type FafbResult<T> = Result<T, FafbError>;