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