1#[derive(Debug, thiserror::Error)]
5#[non_exhaustive]
6pub enum BleError {
7 #[error("TLV8 error: {0}")]
9 Tlv8(#[from] hap_tlv8::Tlv8Error),
10 #[error("crypto error: {0}")]
12 Crypto(#[from] hap_crypto::CryptoError),
13 #[error("model error: {0}")]
15 Model(#[from] hap_model::ModelError),
16 #[error("accessory not found")]
18 AccessoryNotFound,
19 #[error("characteristic (aid={aid}, iid={iid}) not found")]
21 CharacteristicNotFound {
22 aid: u64,
24 iid: u64,
26 },
27 #[error("malformed HAP-BLE PDU: {0}")]
29 MalformedPdu(&'static str),
30 #[error("accessory rejected pairing (status {0})")]
32 PairingRejected(u8),
33 #[error("accessory rejected the request (PDU status {0})")]
35 RequestRejected(u8),
36 #[error("the accessory disconnected")]
38 Disconnected,
39 #[error("BLE backend error: {0}")]
41 Backend(String),
42}
43
44pub type Result<T> = core::result::Result<T, BleError>;
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 fn tlv8_error_converts_via_from() {
53 fn inner() -> Result<()> {
55 let _ = hap_tlv8::Tlv8Map::parse(&[0x01])?; Ok(())
57 }
58 #[allow(clippy::unwrap_used)] let err = inner().unwrap_err();
60 assert!(matches!(err, BleError::Tlv8(_)));
61 }
62
63 #[test]
64 fn char_not_found_displays_ids() {
65 let e = BleError::CharacteristicNotFound { aid: 1, iid: 9 };
66 assert_eq!(e.to_string(), "characteristic (aid=1, iid=9) not found");
67 }
68}