fidl_next_codec/decode/
error.rs1use thiserror::Error;
6
7use crate::ValidationError;
8
9#[derive(Clone, Error, Debug)]
11pub enum DecodeError {
12 #[error("required handle is absent")]
14 RequiredHandleAbsent,
15
16 #[error("required value is absent")]
18 RequiredValueAbsent,
19
20 #[error("`unit` field has an invalid value; expected 0, found {0}")]
22 InvalidUnit(u8),
23
24 #[error("`bool` field has an invalid value; expected 0 or 1, found {0}")]
26 InvalidBool(u8),
27
28 #[error("handle has an invalid presence marker; expected 0 or u32::MAX, found {0}")]
30 InvalidHandlePresence(u32),
31
32 #[error("pointer has an invalid presence marker; expected 0 or u64::MAX, found {0}.")]
34 InvalidPointerPresence(u64),
35
36 #[error("invalid envelope size; expected a multiple of 8, found {0}")]
38 InvalidEnvelopeSize(u32),
39
40 #[error("invalid enum ordinal; expected a valid ordinal, found {0}")]
42 InvalidEnumOrdinal(i128),
43
44 #[error("invalid union ordinal; expected a valid ordinal, found {0}")]
46 InvalidUnionOrdinal(usize),
47
48 #[error("invalid bits; expected a subset of {expected:b}, found {actual:b}")]
50 InvalidBits {
51 expected: usize,
53 actual: usize,
55 },
56
57 #[error(
59 "envelope has out-of-line data which is too small; expected more than 4 bytes out-of-line, \
60 found {0} bytes"
61 )]
62 OutOfLineValueTooSmall(u32),
63
64 #[error(
66 "envelope has inline data which is too big; expected 4 bytes or fewer, found {0} bytes"
67 )]
68 InlineValueTooBig(usize),
69
70 #[error("envelope should always be inline, but it contained {0} out-of-line bytes")]
72 ExpectedInline(usize),
73
74 #[error(
76 "envelope consumed a different number of handles than it claimed that it would; expected \
77 {expected} to be consumed, found {actual} were consumed"
78 )]
79 IncorrectNumberOfHandlesConsumed {
80 expected: usize,
82 actual: usize,
84 },
85
86 #[error("invalid envelope flags: {0:#b}")]
88 InvalidEnvelopeFlags(u16),
89
90 #[error("optional value is absent but has a non-zero size; expected 0, found {0}")]
92 InvalidOptionalSize(u64),
93
94 #[error(
96 "vector has a length greater than the allowed limit; expected no more than {limit} \
97 elements, found {size} elements"
98 )]
99 VectorTooLong {
100 size: u64,
102 limit: u64,
104 },
105
106 #[error("string has non-UTF8 content; {0}")]
108 InvalidUtf8(#[from] core::str::Utf8Error),
109
110 #[error("union is absent but has a non-zero envelope")]
112 InvalidUnionEnvelope,
113
114 #[error("framework error has an unrecognized error code")]
116 InvalidFrameworkError(i32),
117
118 #[error("reached the end of the buffer before decoding finished")]
120 InsufficientData,
121
122 #[error("consumed all handles before decoding finished")]
124 InsufficientHandles,
125
126 #[error("cannot decode driver handles with this decoder")]
128 DriverHandlesUnsupported,
129
130 #[error("expected next handle to be a driver handle")]
132 ExpectedDriverHandle,
133
134 #[error("expected next handle to be a zircon handle")]
136 ExpectedZirconHandle,
137
138 #[error(
140 "finished decoding before all bytes were consumed; completed with {num_extra} bytes left \
141 over"
142 )]
143 ExtraBytes {
144 num_extra: usize,
146 },
147
148 #[error(
150 "finished decoding before all handles were consumed; completed with {num_extra} handles \
151 left over"
152 )]
153 ExtraHandles {
154 num_extra: usize,
156 },
157
158 #[error("invalid empty struct")]
160 InvalidEmptyStruct,
161
162 #[error("invalid padding")]
164 InvalidPadding,
165
166 #[error("validation failed")]
168 Validation(#[from] ValidationError),
169}