cedar_policy_core/entities/
err.rsuse super::EntityUID;
use crate::transitive_closure;
use miette::Diagnostic;
use thiserror::Error;
#[derive(Debug, Diagnostic, Error)]
pub enum EntitiesError {
#[error("error during entity serialization")]
#[diagnostic(transparent)]
Serialization(#[from] crate::entities::json::err::JsonSerializationError),
#[error("error during entity deserialization")]
#[diagnostic(transparent)]
Deserialization(#[from] crate::entities::json::err::JsonDeserializationError),
#[error(transparent)]
#[diagnostic(transparent)]
Duplicate(Duplicate),
#[error("transitive closure computation/enforcement error")]
#[diagnostic(transparent)]
TransitiveClosureError(#[from] TransitiveClosureError),
#[error("entity does not conform to the schema")]
#[diagnostic(transparent)]
InvalidEntity(#[from] crate::entities::conformance::err::EntitySchemaConformanceError),
}
impl EntitiesError {
pub(crate) fn duplicate(euid: EntityUID) -> Self {
Self::Duplicate(Duplicate { euid })
}
}
impl From<transitive_closure::TcError<EntityUID>> for EntitiesError {
fn from(value: transitive_closure::TcError<EntityUID>) -> Self {
let tc: TransitiveClosureError = value.into();
tc.into()
}
}
#[derive(Debug, Error, Diagnostic)]
#[error(transparent)]
#[diagnostic(transparent)]
pub struct TransitiveClosureError {
err: Box<transitive_closure::TcError<EntityUID>>,
}
impl TransitiveClosureError {
#[cfg(test)]
pub(crate) fn inner(&self) -> &transitive_closure::TcError<EntityUID> {
self.err.as_ref()
}
}
impl From<transitive_closure::TcError<EntityUID>> for TransitiveClosureError {
fn from(v: transitive_closure::TcError<EntityUID>) -> Self {
Self { err: Box::new(v) }
}
}
#[derive(Debug, PartialEq, Eq, Error, Diagnostic)]
#[error("duplicate entity entry `{}`", .euid)]
pub struct Duplicate {
euid: EntityUID,
}
impl Duplicate {
#[cfg(test)]
pub(crate) fn euid(&self) -> &EntityUID {
&self.euid
}
}
pub type Result<T> = std::result::Result<T, EntitiesError>;