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