Skip to main content

vitaminc_prf/
error.rs

1use thiserror::Error;
2
3/// Errors detected while a structured PRF program is being built.
4#[derive(Debug, Clone, PartialEq, Eq, Error)]
5pub enum PrfBuildError {
6    #[error("a map value was supplied without a preceding key")]
7    ValueWithoutKey,
8    #[error("a map key was supplied before the preceding key received a value")]
9    KeyWithoutValue,
10    #[error("a map ended while a key was still waiting for a value")]
11    DanglingKey,
12    #[error("a map key was supplied more than once")]
13    DuplicateKey,
14    #[error("the backend rejected a boxed passthrough value")]
15    InvalidPassthrough,
16}
17
18/// Errors produced when a visitor is used with the wrong resolved shape.
19#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
20pub enum PrfVisitorError {
21    #[error("the PRF result had an unexpected structural shape")]
22    UnexpectedShape,
23    #[error("the PRF result could not be converted to the requested value")]
24    InvalidValue,
25}
26
27/// A structured PRF failure.
28///
29/// Builder and visitor failures describe malformed local structure. Backend
30/// failures describe execution of an otherwise valid program (for example, a
31/// remote batch request being rejected).
32#[derive(Debug, PartialEq, Eq, Error)]
33pub enum PrfError<E> {
34    #[error("failed to build PRF operation: {0}")]
35    Build(#[from] PrfBuildError),
36    #[error("failed to interpret PRF result: {0}")]
37    Visitor(#[from] PrfVisitorError),
38    #[error("PRF backend failed: {0}")]
39    Backend(E),
40}