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 /// A well-formed evolved value cannot satisfy the required projection.
35 #[cfg(feature = "evolution")]
36 Incompatible,
37}
38
39impl core::fmt::Display for Error {
40 fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
41 formatter.write_str(match self {
42 Self::Limit(LimitKind::Bytes) => "wire bytes limit",
43 Self::Limit(LimitKind::Allocation) => "wire allocation limit",
44 Self::Limit(LimitKind::Nodes) => "wire nodes limit",
45 Self::Limit(LimitKind::Depth) => "wire depth limit",
46 Self::Limit(LimitKind::Output) => "wire output limit",
47 Self::Limit(LimitKind::Field) => "wire field limit",
48 Self::Allocation => "wire allocation",
49 Self::Malformed => "wire malformed",
50 Self::Trailing => "wire trailing",
51 Self::Identity => "wire identity",
52 #[cfg(feature = "evolution")]
53 Self::Incompatible => "wire incompatible",
54 })
55 }
56}
57
58impl core::error::Error for Error {}