rubble/
error.rs

1use core::fmt;
2
3/// Errors returned by the BLE stack.
4#[derive(Debug, PartialEq, Eq)]
5#[non_exhaustive]
6pub enum Error {
7    /// Packet specified an invalid length value or was too short.
8    ///
9    /// This indicates a protocol violation, so the connection should
10    /// considered lost (if one is currently established).
11    InvalidLength,
12
13    /// Invalid value supplied for field.
14    InvalidValue,
15
16    /// Unexpectedly reached EOF while reading or writing data.
17    ///
18    /// This is returned when the application tries to fit too much data into a
19    /// PDU or other fixed-size buffer, and also when reaching EOF prematurely
20    /// while reading data from a buffer.
21    Eof,
22
23    /// Parsing didn't consume the entire buffer.
24    IncompleteParse,
25}
26
27impl fmt::Display for Error {
28    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29        f.write_str(match self {
30            Error::InvalidLength => "invalid length value specified",
31            Error::InvalidValue => "invalid value for field",
32            Error::Eof => "end of buffer",
33            Error::IncompleteParse => "excess data in buffer",
34        })
35    }
36}