fidl_next_codec/decode/
error.rs1use thiserror::Error;
6
7#[derive(Clone, Error, Debug)]
9pub enum DecodeError {
10    #[error("required handle is absent")]
12    RequiredHandleAbsent,
13
14    #[error("required value is absent")]
16    RequiredValueAbsent,
17
18    #[error("`bool` field has an invalid value; expected 0 or 1, found {0}")]
20    InvalidBool(u8),
21
22    #[error("handle has an invalid presence marker; expected 0 or u32::MAX, found {0}")]
24    InvalidHandlePresence(u32),
25
26    #[error("pointer has an invalid presence marker; expected 0 or u64::MAX, found {0}.")]
28    InvalidPointerPresence(u64),
29
30    #[error("invalid envelope size; expected a multiple of 8, found {0}")]
32    InvalidEnvelopeSize(u32),
33
34    #[error("invalid enum ordinal; expected a valid ordinal, found {0}")]
36    InvalidEnumOrdinal(i128),
37
38    #[error("invalid union ordinal; expected a valid ordinal, found {0}")]
40    InvalidUnionOrdinal(usize),
41
42    #[error("invalid bits; expected a subset of {expected:b}, found {actual:b}")]
44    InvalidBits {
45        expected: usize,
47        actual: usize,
49    },
50
51    #[error(
53        "envelope has out-of-line data which is too small; expected more than 4 bytes out-of-line, \
54        found {0} bytes"
55    )]
56    OutOfLineValueTooSmall(u32),
57
58    #[error(
60        "envelope has inline data which is too big; expected 4 bytes or fewer, found {0} bytes"
61    )]
62    InlineValueTooBig(usize),
63
64    #[error("envelope should always be inline, but it contained {0} out-of-line bytes")]
66    ExpectedInline(usize),
67
68    #[error(
70        "envelope consumed a different number of handles than it claimed that it would; expected \
71        {expected} to be consumed, found {actual} were consumed"
72    )]
73    IncorrectNumberOfHandlesConsumed {
74        expected: usize,
76        actual: usize,
78    },
79
80    #[error("invalid envelope flags: {0:#b}")]
82    InvalidEnvelopeFlags(u16),
83
84    #[error("optional value is absent but has a non-zero size; expected 0, found {0}")]
86    InvalidOptionalSize(u64),
87
88    #[error(
90        "vector has a length greater than the allowed limit; expected no more than {limit} \
91        elements, found {size} elements"
92    )]
93    VectorTooLong {
94        size: u64,
96        limit: u64,
98    },
99
100    #[error("string has non-UTF8 content; {0}")]
102    InvalidUtf8(#[from] core::str::Utf8Error),
103
104    #[error("union is absent but has a non-zero envelope")]
106    InvalidUnionEnvelope,
107
108    #[error("framework error has an unrecognized error code")]
110    InvalidFrameworkError(i32),
111
112    #[error("reached the end of the buffer before decoding finished")]
114    InsufficientData,
115
116    #[error("consumed all handles before decoding finished")]
118    InsufficientHandles,
119
120    #[error("cannot decode driver handles with this decoder")]
122    DriverHandlesUnsupported,
123
124    #[error("expected next handle to be a driver handle")]
126    ExpectedDriverHandle,
127
128    #[error("expected next handle to be a zircon handle")]
130    ExpectedZirconHandle,
131
132    #[error(
134        "finished decoding before all bytes were consumed; completed with {num_extra} bytes left \
135        over"
136    )]
137    ExtraBytes {
138        num_extra: usize,
140    },
141
142    #[error(
144        "finished decoding before all handles were consumed; completed with {num_extra} handles \
145        left over"
146    )]
147    ExtraHandles {
148        num_extra: usize,
150    },
151
152    #[error("invalid empty struct")]
154    InvalidEmptyStruct,
155
156    #[error("invalid padding")]
158    InvalidPadding,
159
160    #[error("validation failed")]
162    Validation(#[from] crate::ValidationError),
163}