Skip to main content

simple_someip/protocol/sd/
error.rs

1use thiserror::Error;
2
3/// Errors that can occur when parsing or validating SOME/IP-SD messages.
4#[derive(Error, Debug)]
5pub enum Error {
6    /// The entry type byte is not a recognized SD entry type.
7    #[error("Invalid value for Service Discovery entry type: {0:X}")]
8    InvalidEntryType(u8),
9    /// The option type byte is not a recognized SD option type.
10    #[error("Invalid value for Service Discovery Option Type: {0:X}")]
11    InvalidOptionType(u8),
12    /// The transport protocol byte is not a recognized value.
13    #[error("Invalid value for Service Discovery Option Transport Protocol: {0:X}")]
14    InvalidOptionTransportProtocol(u8),
15    /// The declared options size does not match the actual data.
16    #[error("Incorrect options size, {0} bytes remaining")]
17    IncorrectOptionsSize(usize),
18    /// An option's length field does not match the expected size for its type.
19    #[error(
20        "Invalid SD option length for type 0x{option_type:02X}: expected {expected}, got {actual}"
21    )]
22    InvalidOptionLength {
23        /// The option type byte.
24        option_type: u8,
25        /// The expected length value.
26        expected: u16,
27        /// The actual length value found.
28        actual: u16,
29    },
30    /// A configuration string exceeds the maximum allowed length.
31    #[error("Configuration string too long: {0} bytes")]
32    ConfigurationStringTooLong(usize),
33    /// An SD message failed structural validation.
34    #[error("Invalid SD message: {0}")]
35    InvalidMessage(&'static str),
36    /// The entries array length is not a multiple of the entry size (16 bytes).
37    #[error("Entries array length {0} is not a multiple of entry size (16)")]
38    IncorrectEntriesSize(usize),
39}