use thiserror::Error;
#[derive(Error, Debug)]
pub enum FafbError {
#[error("Invalid magic number: expected FAFB (0x46414642), got {0:#010x}")]
InvalidMagic(u32),
#[error("Incompatible version: expected major version {expected}, got {actual}")]
IncompatibleVersion { expected: u8, actual: u8 },
#[error("Checksum mismatch: expected {expected:#010x}, got {actual:#010x}")]
ChecksumMismatch { expected: u32, actual: u32 },
#[error("File too small: expected at least {expected} bytes, got {actual}")]
FileTooSmall { expected: usize, actual: usize },
#[error("Invalid section table offset: {offset} exceeds file size {file_size}")]
InvalidSectionTableOffset { offset: u32, file_size: u32 },
#[error("Section count {count} exceeds maximum {max}")]
TooManySections { count: u16, max: u16 },
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
#[error("Size mismatch: header says {header_size} bytes, actual {actual_size}")]
SizeMismatch {
header_size: u32,
actual_size: usize,
},
#[error("String table index {index} out of bounds (table has {count} entries)")]
StringTableIndexOutOfBounds { index: u8, count: u16 },
#[error("String table entry too long: {length} bytes exceeds maximum {max}")]
StringTableEntryTooLong { length: usize, max: usize },
#[error("String table full: maximum {max} entries")]
StringTableFull { max: usize },
#[error("Missing string table section (required for FAFb v2)")]
MissingStringTable,
#[error("Invalid UTF-8 in string table: {0}")]
InvalidUtf8(String),
}
pub type FafbResult<T> = Result<T, FafbError>;