use miette::Diagnostic;
use ref_cast::RefCast;
use thiserror::Error;
use crate::PolicyId;
#[cfg(doc)]
use crate::ValidationError;
macro_rules! wrap_core_error {
($s:ident) => {
#[derive(Debug, Clone, Error, Diagnostic)]
#[error(transparent)]
#[diagnostic(transparent)]
#[doc=concat!("Structure containing details about a [`ValidationError::", stringify!($s), "`].")]
pub struct $s(cedar_policy_core::validator::validation_errors::$s);
impl $s {
pub fn policy_id(&self) -> &PolicyId {
PolicyId::ref_cast(&self.0.policy_id)
}
}
#[doc(hidden)]
impl From<cedar_policy_core::validator::validation_errors::$s> for $s {
fn from(e: cedar_policy_core::validator::validation_errors::$s) -> Self {
Self(e)
}
}
};
}
wrap_core_error!(UnrecognizedEntityType);
wrap_core_error!(UnrecognizedActionId);
wrap_core_error!(InvalidActionApplication);
wrap_core_error!(UnexpectedType);
wrap_core_error!(IncompatibleTypes);
wrap_core_error!(UnsafeAttributeAccess);
wrap_core_error!(UnsafeOptionalAttributeAccess);
wrap_core_error!(UnsafeTagAccess);
wrap_core_error!(NoTagsAllowed);
wrap_core_error!(UndefinedFunction);
wrap_core_error!(WrongNumberArguments);
wrap_core_error!(FunctionArgumentValidation);
wrap_core_error!(HierarchyNotRespected);
wrap_core_error!(EntityDerefLevelViolation);
wrap_core_error!(EmptySetForbidden);
wrap_core_error!(NonLitExtConstructor);
wrap_core_error!(InternalInvariantViolation);
wrap_core_error!(InvalidEnumEntity);