matter_interaction/error.rs
1//! Error type for Interaction Model framing.
2
3#![forbid(unsafe_code)]
4
5use thiserror::Error;
6
7/// Errors produced while building or parsing Interaction Model messages.
8#[derive(Debug, Error)]
9#[non_exhaustive]
10pub enum ImError {
11 /// Underlying TLV decode failure.
12 #[error("TLV codec error: {0}")]
13 Codec(#[from] matter_codec::Error),
14
15 /// The message's outermost element was not the expected anonymous struct.
16 #[error("expected anonymous structure at message root")]
17 NotAStruct,
18
19 /// A required field was absent from the message.
20 #[error("missing required IM field: {0}")]
21 MissingField(&'static str),
22
23 /// A field held a TLV value of an unexpected type.
24 #[error("unexpected TLV value for IM field: {0}")]
25 UnexpectedValue(&'static str),
26
27 /// An `InvokeResponseIB` contained neither a Command nor a Status member.
28 #[error("InvokeResponseIB had neither Command nor Status")]
29 EmptyInvokeResponse,
30
31 /// A `StatusIB.Status` field was present on the wire but carried a value
32 /// outside the valid Matter status-code range (`0x00..=0xFF`, a single
33 /// octet per Matter Core Spec ยง8.10). The raw decoded value is preserved
34 /// so callers can log the malformed code. This is deliberately distinct
35 /// from [`MissingField`](Self::MissingField): the field *was* present, it
36 /// was simply out of range, and conflating the two would mislead a caller
37 /// diagnosing a non-conformant device.
38 #[error("StatusIB.Status out of range: {code} (valid 0x00..=0xFF)")]
39 InvalidStatusCode {
40 /// The raw, out-of-range status value as decoded from the wire.
41 code: u64,
42 },
43
44 /// A [`ReportAccumulator`](crate::ReportAccumulator) exceeded its in-crate
45 /// total-size ceiling while merging chunked `ReportData`. This is
46 /// defense-in-depth against a peer streaming an unbounded chunked
47 /// read/report set: the accumulator caps both the number of distinct
48 /// accumulated elements and an estimate of their total in-memory byte
49 /// size, returning this error rather than growing without bound.
50 #[error(
51 "ReportAccumulator ceiling exceeded: {elements} elements / ~{bytes} bytes \
52 (max {max_elements} elements / {max_bytes} bytes)"
53 )]
54 AccumulatorOverflow {
55 /// Distinct accumulated elements at the point the cap was hit.
56 elements: usize,
57 /// Estimated total accumulated byte size at the point the cap was hit.
58 bytes: usize,
59 /// The configured maximum element count.
60 max_elements: usize,
61 /// The configured maximum estimated byte size.
62 max_bytes: usize,
63 },
64}