matter_clusters/error.rs
1//! Errors surfaced by generated cluster codecs.
2
3use matter_codec::Error as TlvError;
4
5/// Error returned by a generated attribute/command/struct decoder.
6///
7/// Deliberately has **no** `InvalidEnumValue` variant: unknown enum
8/// discriminants decode to the enum's `Unknown(n)` variant, never an error
9/// (forward compatibility — a device on a newer spec revision must not break
10/// our decode).
11#[derive(Debug, thiserror::Error)]
12#[non_exhaustive]
13pub enum ClusterError {
14 /// The underlying TLV codec rejected the bytes.
15 #[error("TLV codec error: {0}")]
16 Tlv(#[from] TlvError),
17
18 /// A TLV element had a type we did not expect for this field.
19 #[error("unexpected TLV type for {context}")]
20 UnexpectedType {
21 /// Where the mismatch occurred (e.g. `"OnOff::OnTime"`).
22 context: &'static str,
23 },
24
25 /// A required struct/command field was absent.
26 #[error("missing required field: {0}")]
27 MissingField(&'static str),
28
29 /// An integer or list length did not fit its declared Rust width.
30 #[error("value out of range for {0}")]
31 InvalidLength(&'static str),
32}