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: need {needed} bytes, have {available}")]
18    IncorrectOptionsSize {
19        /// The number of bytes required for the option header or body.
20        needed: usize,
21        /// The number of bytes actually remaining in the buffer.
22        available: usize,
23    },
24    /// An option's length field does not match the expected size for its type.
25    #[error(
26        "Invalid SD option length for type 0x{option_type:02X}: expected {expected}, got {actual}"
27    )]
28    InvalidOptionLength {
29        /// The option type byte.
30        option_type: u8,
31        /// The expected length value.
32        expected: u16,
33        /// The actual length value found.
34        actual: u16,
35    },
36    /// A configuration string exceeds the maximum allowed length.
37    #[error("Configuration string too long: {0} bytes")]
38    ConfigurationStringTooLong(usize),
39    /// An SD message failed structural validation.
40    #[error("Invalid SD message: {0}")]
41    InvalidMessage(&'static str),
42    /// The entries array length is not a multiple of the entry size (16 bytes).
43    #[error("Entries array length {0} is not a multiple of entry size (16)")]
44    IncorrectEntriesSize(usize),
45}