1use cedar_policy::{
2 ContextCreationError, EntityAttrEvaluationError, ParseErrors, RequestValidationError,
3 entities_errors::EntitiesError,
4};
5use serde::{Deserialize, Serialize};
6use thiserror::Error;
7
8#[derive(Debug, Error, Serialize, Deserialize)]
14#[non_exhaustive]
15pub enum PolicyError {
16 #[error("failed to parse policy: {0}")]
18 ParseError(String),
19
20 #[error("evaluation error: {0}")]
22 EvalError(String),
23
24 #[error("request validation error: {0}")]
26 RequestValidationError(String),
27
28 #[error("context creation error: {0}")]
30 ContextError(String),
31
32 #[error("entity error: {0}")]
34 EntityError(String),
35
36 #[error("invalid format: {0}")]
38 InvalidFormat(String),
39
40 #[error("entity attribute error: {0}")]
42 EntityAttrError(String),
43}
44
45impl From<RequestValidationError> for PolicyError {
46 fn from(err: cedar_policy::RequestValidationError) -> Self {
47 PolicyError::RequestValidationError(err.to_string())
48 }
49}
50
51impl From<ParseErrors> for PolicyError {
52 fn from(err: ParseErrors) -> Self {
53 PolicyError::ParseError(err.to_string())
54 }
55}
56
57impl From<ContextCreationError> for PolicyError {
58 fn from(err: ContextCreationError) -> Self {
59 PolicyError::ContextError(err.to_string())
60 }
61}
62
63impl From<EntityAttrEvaluationError> for PolicyError {
64 fn from(err: EntityAttrEvaluationError) -> Self {
65 PolicyError::EntityAttrError(err.to_string())
66 }
67}
68
69impl From<EntitiesError> for PolicyError {
70 fn from(err: EntitiesError) -> Self {
71 PolicyError::EntityError(err.to_string())
72 }
73}