Skip to main content

rullst_core/client_contract/
error.rs

1use thiserror::Error;
2
3/// Fail-closed client-contract validation or codec error.
4#[derive(Debug, Error)]
5#[non_exhaustive]
6pub enum ClientContractError {
7    /// Wire versions must be positive.
8    #[error("client contract version must be positive")]
9    InvalidVersion,
10    /// Request identifiers must satisfy the bounded token grammar.
11    #[error("client request id must be a 1-128 byte ASCII token")]
12    InvalidRequestId,
13    /// Mutation replay keys must satisfy the bounded token grammar.
14    #[error("client idempotency key must be an 8-128 byte ASCII token")]
15    InvalidIdempotencyKey,
16    /// Failure codes must use the stable dotted grammar.
17    #[error("client failure code must be a bounded lowercase dotted identifier")]
18    InvalidFailureCode,
19    /// A negotiation offer contained no version.
20    #[error("client version offer must not be empty")]
21    EmptyVersionOffer,
22    /// A negotiation offer exceeded its structural bound.
23    #[error("client version offer exceeds 16 entries")]
24    TooManyOfferedVersions,
25    /// Server policy range or body limit is invalid.
26    #[error("client contract policy range or body limit is invalid")]
27    InvalidPolicy,
28    /// Client and server share no supported version.
29    #[error("client and server have no mutually supported contract version")]
30    NoMutualVersion,
31    /// A request or response selected a version outside server policy.
32    #[error(
33        "client contract version {received} is outside the supported range {minimum}..={current}"
34    )]
35    UnsupportedVersion {
36        /// Received version.
37        received: u16,
38        /// Minimum supported version.
39        minimum: u16,
40        /// Latest supported version.
41        current: u16,
42    },
43    /// A state-changing request omitted its replay key.
44    #[error("client mutation requires an idempotency key")]
45    MissingIdempotencyKey,
46    /// Encoded content exceeded the policy ceiling.
47    #[error("client contract body exceeds the {maximum}-byte maximum")]
48    BodyTooLarge {
49        /// Configured maximum size.
50        maximum: usize,
51    },
52    /// Incoming JSON did not satisfy the typed envelope.
53    #[error("client contract JSON is invalid")]
54    InvalidJson(#[source] serde_json::Error),
55    /// A typed response could not be serialized.
56    #[error("client contract JSON encoding failed")]
57    EncodeJson(#[source] serde_json::Error),
58}