Skip to main content

khive_gate/
error.rs

1use thiserror::Error;
2
3// ---------- Validation error ----------
4
5/// Validation error for gate wire types.
6///
7/// Returned by `try_new` constructors and custom `Deserialize` impls when
8/// invariants are violated (empty fields, zero rate-limit values).
9#[derive(Error, Debug, Clone, PartialEq, Eq)]
10pub enum GateValidationError {
11    #[error("actor kind must not be empty")]
12    EmptyActorKind,
13    #[error("actor id must not be empty")]
14    EmptyActorId,
15    #[error("verb must not be empty")]
16    EmptyVerb,
17    #[error("deny reason must not be empty")]
18    EmptyDenyReason,
19    #[error("audit tag must not be empty")]
20    EmptyAuditTag,
21    #[error("rate limit window_secs must be > 0")]
22    ZeroRateLimitWindow,
23    #[error("rate limit max must be > 0")]
24    ZeroRateLimitMax,
25}
26
27// ---------- Error ----------
28
29/// Errors returned by [`crate::Gate::check`].
30#[derive(Error, Debug)]
31pub enum GateError {
32    #[error("policy error: {0}")]
33    Policy(String),
34    #[error("internal gate error: {0}")]
35    Internal(String),
36    #[error("validation error: {0}")]
37    Validation(#[from] GateValidationError),
38}