1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use std::{io, num, str, sync::mpsc};
use thiserror::Error;

use crate::characteristic::Format;

/// HAP error representation.
#[derive(Debug, Error)]
pub enum Error {
    // custom errors
    #[error("The PIN is too easy. The following PINs are not allowed: []")]
    PinTooEasy,
    #[error("The PIN contains invalid digits. You may only use numbers from 0 to 9.")]
    InvalidPin,
    #[error(
        "Invalid pairing permission Byte: {0}. Only `Permissions::User = 0x00` and `Permissions::Admin = 0x01` are allowed."
    )]
    InvalidPairingPermission(u8),
    #[error("The value is below the `min_value` of the characteristic.")]
    ValueBelowMinValue,
    #[error("The value is above the `max_value` of the characteristic.")]
    ValueAboveMaxValue,
    #[error("The selected accessory is not present on the server.")]
    AccessoryNotFound,
    #[error("The provided accessory was already added to the server.")]
    DuplicateAccessory,
    #[error(
        "The provided value has an invalid data type for the characteristic. The characteristic's format is {0:?}."
    )]
    InvalidValue(Format),
    #[error("Invalid HapType string value: `{0}`.")]
    InvalidHapTypeString(String),

    // converted errors
    #[error("IO Error: {0}")]
    Io(#[from] io::Error),
    #[error("Serde JSON Error: {0}")]
    Json(#[from] serde_json::Error),
    #[error("HTTP Status Code: {0}")]
    HttpStatus(hyper::StatusCode),
    #[error("Hyper HTTP Error: {0}")]
    Http(#[from] hyper::http::Error),
    #[error("Hyper Error: {0}")]
    Hyper(#[from] hyper::Error),
    #[error("Task Join Error: {0}")]
    TaskJoin(#[from] tokio::task::JoinError),
    #[error("AEAD Error")]
    Aead,
    #[error("HKDF Invalid Length Error")]
    HkdfInvalidLength,
    #[error("UTF-8 Error: {0}")]
    Utf8(#[from] str::Utf8Error),
    #[error("Parse EUI-48 Error: {0}")]
    ParseEui48(#[from] eui48::ParseError),
    #[error("Parse Int Error: {0}")]
    ParseInt(#[from] num::ParseIntError),
    #[error("MPSC Send Error: {0}")]
    MpscSend(#[from] mpsc::SendError<()>),
}

impl From<aead::Error> for Error {
    fn from(_: aead::Error) -> Self { Error::Aead }
}