1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/// Errors that can occur while encoding (packing) a value to wire format.
#[derive(Debug, Clone, PartialEq, thiserror::Error)]
pub enum EncodeError {
/// A field value does not fit in the declared bit width.
#[error("field `{field}`: value does not fit in {bits} bits")]
ValueOutOfRange { field: &'static str, bits: u8 },
/// A collection or byte sequence exceeds its maximum allowed length.
#[error("field `{field}`: length {actual} exceeds limit {limit}")]
LimitExceeded {
field: &'static str,
limit: u64,
actual: u64,
},
/// Recursive type nesting exceeded [`MAX_RECURSION_DEPTH`](crate::MAX_RECURSION_DEPTH).
#[error("recursive type nesting exceeded 64 levels")]
RecursionLimitExceeded,
/// A field value violated a where clause constraint.
#[error("field `{field}`: constraint violation: {message}")]
ConstraintViolation {
field: &'static str,
message: String,
},
}
/// Errors that can occur while decoding (unpacking) a value from wire format.
#[derive(Debug, Clone, PartialEq, thiserror::Error)]
pub enum DecodeError {
/// The input ended before all expected fields were read.
#[error("unexpected end of input")]
UnexpectedEof,
/// A string field contained bytes that are not valid UTF-8.
#[error("invalid UTF-8 in string field")]
InvalidUtf8,
/// A LEB128 varint was too long or used an overlong encoding.
#[error("invalid or overlong varint encoding")]
InvalidVarint,
/// A decoded length or count exceeded its safety limit.
#[error("field `{field}`: length {actual} exceeds limit {limit}")]
LimitExceeded {
field: &'static str,
limit: u64,
actual: u64,
},
/// The discriminant for an enum did not match any known variant.
#[error("unknown enum variant {value} for type `{type_name}`")]
UnknownEnumVariant { type_name: &'static str, value: u64 },
/// The discriminant for a union did not match any known variant.
#[error("unknown union variant {discriminant} for type `{type_name}`")]
UnknownUnionVariant {
type_name: &'static str,
discriminant: u64,
},
/// A field that was marked as removed in the schema was encountered.
#[error("decoded removed field ordinal {ordinal} (removed in {removed_in}): {reason}")]
RemovedField {
ordinal: u16,
removed_in: &'static str,
reason: &'static str,
},
/// A field value was syntactically valid but semantically invalid.
#[error("field `{field}`: {message}")]
InvalidValue {
field: &'static str,
message: String,
},
/// Recursive type nesting exceeded [`MAX_RECURSION_DEPTH`](crate::MAX_RECURSION_DEPTH).
#[error("recursive type nesting exceeded 64 levels")]
RecursionLimitExceeded,
/// The BLAKE3 schema hash in the data did not match the local schema.
#[error("schema hash mismatch")]
SchemaMismatch { local: [u8; 32], remote: [u8; 32] },
}