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