Skip to main content

zigbee_host/
error.rs

1//! Host errors.
2
3use zigbee_primitives::{Ieee, NodeId};
4
5/// A host operation failed.
6#[derive(Debug, Clone, thiserror::Error)]
7pub enum HostError {
8    /// The NCP failed or rejected a command.
9    #[error("NCP: {0}")]
10    Ncp(String),
11    /// The NCP runs a different network than configured. Nothing was
12    /// changed; restore a backup or allow replacing it.
13    #[error("the coordinator runs another network ({found}); refusing to replace it")]
14    NetworkMismatch {
15        /// What the NCP has.
16        found: String,
17    },
18    /// A restore needs the coordinator's IEEE address and this chip cannot
19    /// take it.
20    #[error("cannot restore: {0}")]
21    RestoreRefused(String),
22    /// The coordinator's IEEE address was written; the NCP must be power
23    /// cycled (or the host restarted) before the restore can finish.
24    #[error("coordinator IEEE address written; restart to finish the restore")]
25    RestartRequired,
26    /// No such device.
27    #[error("unknown device {0}")]
28    UnknownDevice(Ieee),
29    /// The device did not answer in time.
30    #[error("no response from {0:#06x}")]
31    Timeout(NodeId),
32    /// The NCP could not deliver the frame.
33    #[error("delivery to {0:#06x} failed")]
34    DeliveryFailed(NodeId),
35    /// The device answered with a failure status.
36    #[error("{what} failed with status {status:#04x}")]
37    Status {
38        /// The request.
39        what: String,
40        /// The status.
41        status: u8,
42    },
43    /// A frame did not decode.
44    #[error("bad frame: {0}")]
45    BadFrame(String),
46    /// A request was not valid.
47    #[error("{0}")]
48    Invalid(String),
49    /// Store or backup file I/O.
50    #[error("{0}")]
51    Io(String),
52    /// The host has stopped.
53    #[error("host stopped")]
54    Stopped,
55}
56
57impl From<zigbee_ezsp::EzspError> for HostError {
58    fn from(e: zigbee_ezsp::EzspError) -> Self {
59        HostError::Ncp(e.to_string())
60    }
61}