Skip to main content

waratah_proto/
error.rs

1//! Typed wire-decoding errors.
2
3use thiserror::Error;
4use waratah_storage::StorageError;
5
6/// Failure decoding a `waratah.v1` message into storage-layer types.
7#[derive(Debug, Error)]
8pub enum ProtoError {
9    /// A `message`-typed field required by the RPC was absent.
10    #[error("missing required field: {0}")]
11    MissingField(&'static str),
12
13    /// Encoded term bytes could not be decoded.
14    #[error("invalid encoded term: {0}")]
15    Term(#[from] StorageError),
16
17    /// A term slot carried more bytes than one encoded term.
18    #[error("{0} trailing byte(s) after encoded term")]
19    TrailingTermBytes(usize),
20
21    /// A `StrHash` field was not exactly 16 big-endian bytes.
22    #[error("StrHash must be 16 bytes, got {0}")]
23    StrHashLength(usize),
24
25    /// An enum field the RPC requires was left at its `UNSPECIFIED` default.
26    #[error("enum field {0} is unspecified")]
27    UnspecifiedEnum(&'static str),
28
29    /// An enum field carries a value this build does not recognise.
30    #[error("enum field {0} has an unknown value {1}")]
31    UnknownEnum(&'static str, i32),
32
33    /// A field that must carry an encoded term was left empty.
34    #[error("field {0} must carry a non-empty encoded term")]
35    EmptyTerm(&'static str),
36
37    /// A slot comparison named the graph slot, which the wire cannot carry.
38    #[error("slot comparisons cannot target the graph slot")]
39    GraphComparisonSlot,
40
41    /// An `omitted_slots` bitmask named a slot outside subject..graph.
42    #[error("omitted_slots has bits outside the four quad slots: {0:#x}")]
43    SlotMask(u32),
44}
45
46impl From<ProtoError> for tonic::Status {
47    fn from(error: ProtoError) -> Self {
48        Self::invalid_argument(error.to_string())
49    }
50}