scuffle_cedar_policy_codegen/
error.rs

1use cedar_policy_core::ast::Id;
2use cedar_policy_core::validator::{CedarSchemaError, SchemaError};
3
4/// Code generation errors
5#[derive(thiserror::Error, Debug)]
6pub enum CodegenError {
7    /// Multiple types map to the same Id in the schema.
8    #[error("multiple types with name {0}")]
9    DuplicateType(Id),
10    /// Something is unsupported.
11    #[error("unsupported: {0}")]
12    Unsupported(String),
13    /// Multiple actions have the same name.
14    #[error("multiple actions with name {0}")]
15    DuplicateAction(String),
16    /// A reference was not found.
17    #[error("unresolved reference: {0}")]
18    UnresolvedReference(String),
19    /// Expected an entity but found a common type instead.
20    #[error("expected entity not common type of {common_type} when declaring {ty}")]
21    ExpectedEntity {
22        /// The common type's name.
23        common_type: String,
24        /// The object we were declaring.
25        ty: String,
26    },
27    /// Failed to parse cedar schema
28    #[error(transparent)]
29    CedarSchemaError(#[from] Box<CedarSchemaError>),
30    /// Failed to parse json schema
31    #[error(transparent)]
32    SchemaError(#[from] Box<SchemaError>),
33}
34
35impl From<SchemaError> for CodegenError {
36    fn from(value: SchemaError) -> Self {
37        Self::SchemaError(Box::new(value))
38    }
39}
40
41impl From<CedarSchemaError> for CodegenError {
42    fn from(value: CedarSchemaError) -> Self {
43        Self::CedarSchemaError(Box::new(value))
44    }
45}
46
47/// A [Result] type with [CodegenError] as the default error.
48pub type CodegenResult<T, E = CodegenError> = std::result::Result<T, E>;