Skip to main content

sbf_tools/
error.rs

1//! SBF error types
2
3use thiserror::Error;
4
5/// Errors that can occur during SBF parsing
6#[derive(Error, Debug)]
7pub enum SbfError {
8    /// Invalid sync bytes (expected 0x24 0x40)
9    #[error("Invalid sync bytes")]
10    InvalidSync,
11
12    /// CRC checksum mismatch
13    #[error("CRC mismatch: expected {expected:#06x}, got {actual:#06x}")]
14    CrcMismatch { expected: u16, actual: u16 },
15
16    /// Block is incomplete (not enough data)
17    #[error("Incomplete block: need {needed} bytes, have {have}")]
18    IncompleteBlock { needed: usize, have: usize },
19
20    /// Invalid block length (must be >= 8 and divisible by 4)
21    #[error("Invalid block length: {0}")]
22    InvalidLength(u16),
23
24    /// Unknown block ID
25    #[error("Unknown block ID: {0}")]
26    UnknownBlockId(u16),
27
28    /// Block-specific parsing error
29    #[error("Parse error: {0}")]
30    ParseError(String),
31
32    /// I/O error during reading
33    #[error("I/O error: {0}")]
34    Io(#[from] std::io::Error),
35
36    /// End of stream reached
37    #[error("End of stream")]
38    EndOfStream,
39}
40
41/// Result type for SBF operations
42pub type SbfResult<T> = Result<T, SbfError>;