Skip to main content

authz_core/
error.rs

1//! Structured error types for authz-core.
2
3use thiserror::Error;
4
5/// Core error type for all authz operations.
6#[derive(Error, Debug, Clone)]
7pub enum AuthzError {
8    // --- Validation (input) ---
9    #[error("validation: {field} — {message}")]
10    Validation { field: String, message: String },
11
12    // --- Model errors ---
13    #[error("model parse error: {0}")]
14    ModelParse(String),
15
16    #[error("model validation: {0}")]
17    ModelValidation(String),
18
19    #[error("no authorization model found")]
20    ModelNotFound,
21
22    // --- Relationship errors ---
23    #[error("relationship validation: {0}")]
24    RelationshipValidation(String),
25
26    // --- Resolution errors ---
27    #[error("relation '{relation}' not found on type '{object_type}'")]
28    RelationNotFound {
29        object_type: String,
30        relation: String,
31    },
32
33    #[error("max recursion depth exceeded")]
34    MaxDepthExceeded,
35
36    #[error("resolution failed: {0}")]
37    ResolutionError(String),
38
39    // --- Datastore / infrastructure ---
40    #[error("datastore error: {0}")]
41    Datastore(String),
42
43    #[error("cache lock poisoned")]
44    CachePoisoned,
45
46    // --- Internal / catch-all ---
47    #[error("internal error: {0}")]
48    Internal(String),
49}