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("rate limit window_secs must be > 0")]
20    ZeroRateLimitWindow,
21    #[error("rate limit max must be > 0")]
22    ZeroRateLimitMax,
23}
24
25// ---------- Error ----------
26
27/// Errors returned by [`Gate::check`].
28#[derive(Error, Debug)]
29pub enum GateError {
30    #[error("policy error: {0}")]
31    Policy(String),
32    #[error("evaluation error: {0}")]
33    Evaluation(String),
34    #[error("internal gate error: {0}")]
35    Internal(String),
36    #[error("validation error: {0}")]
37    Validation(#[from] GateValidationError),
38}