Skip to main content

vexil_runtime/
error.rs

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