scyph_abac/cedar/error.rs
1//! Cedar policy engine error types.
2//!
3//! Defines [`CedarError`] — failures from AWS Cedar policy parsing, schema validation,
4//! request construction, and authorization evaluation.
5//!
6//! ## Error Hierarchy
7//!
8//! ```text
9//! CedarError
10//! ├── PolicyParse — Cedar policy DSL syntax error
11//! ├── SchemaParse — Cedar schema syntax error
12//! ├── RequestBuild — Entity UID resolution or request construction failure
13//! ├── Evaluation — Cedar evaluator runtime error
14//! └── AccessDenied — Policy returned Decision::Deny (authorization failure)
15//! ```
16//!
17//! `AccessDenied` converts to HTTP 403 Forbidden. All other variants convert to HTTP 500
18//! Internal Server Error — they indicate a server-side configuration or programming error
19//! rather than a client access denial.
20
21use scyph_core::AppError;
22use thiserror::Error;
23
24/// Errors encountered during Cedar policy parsing, schema validation, or request evaluation.
25#[derive(Debug, Error)]
26pub enum CedarError {
27 /// Failed to parse Cedar policy source text.
28 #[error("Policy parse error: {0}")]
29 PolicyParse(String),
30
31 /// Failed to parse Cedar schema text.
32 #[error("Schema parse error: {0}")]
33 SchemaParse(String),
34
35 /// Policies failed static validation against the schema (typos, type
36 /// errors, actions or attributes that do not exist). A startup error.
37 #[error("Policy validation error: {0}")]
38 PolicyValidation(String),
39
40 /// Failed to construct Cedar request or entity container.
41 #[error("Request build error: {0}")]
42 RequestBuild(String),
43
44 /// Evaluation error encountered during authorization.
45 #[error("Evaluation error: {0}")]
46 Evaluation(String),
47
48 /// Authorization evaluation resulted in `Decision::Deny`.
49 #[error("Access denied")]
50 AccessDenied,
51}
52
53impl From<CedarError> for AppError {
54 fn from(e: CedarError) -> Self {
55 match e {
56 CedarError::AccessDenied => AppError::Forbidden("Not Permitted".into()),
57 other => AppError::internal_from(other, "Cedar authorization error"),
58 }
59 }
60}