ic_wire/error.rs
1/// The first allowance that refused an operation.
2#[derive(Clone, Copy, Debug, Eq, PartialEq)]
3pub enum LimitKind {
4 /// Complete encoded or supplied input bytes.
5 Bytes,
6 /// Conservative traversal allocation allowance.
7 Allocation,
8 /// Value and seed visits.
9 Nodes,
10 /// Nested traversal depth.
11 Depth,
12 /// Caller-provided destination capacity.
13 Output,
14 /// Declared field bound in a fallible constructor.
15 Field,
16}
17
18/// Wire failure categories, independent of transport and application errors.
19///
20/// Allocation is reserved for fallible codec-owned output allocation; consumer
21/// deserialization can allocate outside the codec's control.
22#[derive(Clone, Copy, Debug, Eq, PartialEq)]
23pub enum Error {
24 /// A wire, collection, traversal or output allowance was exceeded.
25 Limit(LimitKind),
26 /// Allocation failed within an admitted allowance.
27 Allocation,
28 /// The representation is invalid or truncated.
29 Malformed,
30 /// Input remains after the expected value.
31 Trailing,
32 /// The envelope marker, method identity or direction differs.
33 Identity,
34}
35
36impl core::fmt::Display for Error {
37 fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
38 formatter.write_str(match self {
39 Self::Limit(LimitKind::Bytes) => "wire bytes limit",
40 Self::Limit(LimitKind::Allocation) => "wire allocation limit",
41 Self::Limit(LimitKind::Nodes) => "wire nodes limit",
42 Self::Limit(LimitKind::Depth) => "wire depth limit",
43 Self::Limit(LimitKind::Output) => "wire output limit",
44 Self::Limit(LimitKind::Field) => "wire field limit",
45 Self::Allocation => "wire allocation",
46 Self::Malformed => "wire malformed",
47 Self::Trailing => "wire trailing",
48 Self::Identity => "wire identity",
49 })
50 }
51}
52
53impl core::error::Error for Error {}