use cedar_policy_core::ast::Id;
use cedar_policy_core::validator::{CedarSchemaError, SchemaError};
#[derive(thiserror::Error, Debug)]
pub enum CodegenError {
#[error("multiple types with name {0}")]
DuplicateType(Id),
#[error("unsupported: {0}")]
Unsupported(String),
#[error("multiple actions with name {0}")]
DuplicateAction(String),
#[error("unresolved reference: {0}")]
UnresolvedReference(String),
#[error("expected entity not common type of {common_type} when declaring {ty}")]
ExpectedEntity {
common_type: String,
ty: String,
},
#[error(transparent)]
CedarSchemaError(#[from] Box<CedarSchemaError>),
#[error(transparent)]
SchemaError(#[from] Box<SchemaError>),
}
impl From<SchemaError> for CodegenError {
fn from(value: SchemaError) -> Self {
Self::SchemaError(Box::new(value))
}
}
impl From<CedarSchemaError> for CodegenError {
fn from(value: CedarSchemaError) -> Self {
Self::CedarSchemaError(Box::new(value))
}
}
pub type CodegenResult<T, E = CodegenError> = std::result::Result<T, E>;