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