use crate::{EntityUid, PolicyId};
pub use cedar_policy_core::ast::{
expression_construction_errors, restricted_expr_errors, ContainsUnknown,
ExpressionConstructionError, PartialValueToValueError, RestrictedExpressionError,
};
#[cfg(feature = "entity-manifest")]
use cedar_policy_core::entities::err::EntitiesError;
pub use cedar_policy_core::evaluator::{evaluation_errors, EvaluationError};
pub use cedar_policy_core::extensions::{
extension_function_lookup_errors, ExtensionFunctionLookupError,
};
use cedar_policy_core::{ast, authorizer, est};
pub use cedar_policy_validator::cedar_schema::{schema_warnings, SchemaWarning};
#[cfg(feature = "entity-manifest")]
use cedar_policy_validator::entity_manifest::{
self, FailedAnalysisError, PartialExpressionError, PartialRequestError,
};
pub use cedar_policy_validator::{schema_errors, SchemaError};
use miette::Diagnostic;
use ref_cast::RefCast;
use smol_str::SmolStr;
use thiserror::Error;
use to_cedar_syntax_errors::NameCollisionsError;
#[cfg(feature = "entity-manifest")]
use super::ValidationResult;
pub mod entities_errors {
pub use cedar_policy_core::entities::err::{Duplicate, EntitiesError, TransitiveClosureError};
}
pub mod entities_json_errors {
pub use cedar_policy_core::entities::json::err::{
ActionParentIsNotAction, DuplicateKey, ExpectedExtnValue, ExpectedLiteralEntityRef,
ExtnCall0Arguments, ExtnCall2OrMoreArguments, JsonDeserializationError, JsonError,
JsonSerializationError, MissingImpliedConstructor, MissingRequiredRecordAttr, ParseEscape,
ReservedKey, Residual, TypeMismatch, UnexpectedRecordAttr, UnexpectedRestrictedExprKind,
};
}
pub mod conformance_errors {
pub use cedar_policy_core::entities::conformance::err::{
ActionDeclarationMismatch, EntitySchemaConformanceError, ExtensionFunctionLookup,
InvalidAncestorType, MissingRequiredEntityAttr, TypeMismatch, UndeclaredAction,
UnexpectedEntityAttr, UnexpectedEntityTag, UnexpectedEntityTypeError,
};
}
#[derive(Debug, Diagnostic, PartialEq, Eq, Error, Clone)]
pub enum AuthorizationError {
#[error(transparent)]
#[diagnostic(transparent)]
PolicyEvaluationError(#[from] authorization_errors::PolicyEvaluationError),
}
pub mod authorization_errors {
use crate::{EvaluationError, PolicyId};
use cedar_policy_core::{ast, authorizer};
use miette::Diagnostic;
use ref_cast::RefCast;
use thiserror::Error;
#[derive(Debug, Diagnostic, PartialEq, Eq, Error, Clone)]
#[error("error while evaluating policy `{id}`: {error}")]
pub struct PolicyEvaluationError {
id: ast::PolicyID,
#[diagnostic(transparent)]
error: EvaluationError,
}
impl PolicyEvaluationError {
pub fn policy_id(&self) -> &PolicyId {
PolicyId::ref_cast(&self.id)
}
pub fn inner(&self) -> &EvaluationError {
&self.error
}
pub fn into_inner(self) -> EvaluationError {
self.error
}
}
#[doc(hidden)]
impl From<authorizer::AuthorizationError> for PolicyEvaluationError {
fn from(e: authorizer::AuthorizationError) -> Self {
match e {
authorizer::AuthorizationError::PolicyEvaluationError { id, error } => {
Self { id, error }
}
}
}
}
}
#[doc(hidden)]
impl From<authorizer::AuthorizationError> for AuthorizationError {
fn from(value: authorizer::AuthorizationError) -> Self {
Self::PolicyEvaluationError(value.into())
}
}
#[derive(Debug, Diagnostic, Error)]
#[error(transparent)]
#[diagnostic(transparent)]
pub struct ConcretizationError(pub(crate) cedar_policy_core::authorizer::ConcretizationError);
#[derive(Debug, Diagnostic, Error)]
pub enum ReauthorizationError {
#[error(transparent)]
#[diagnostic(transparent)]
Evaluation(#[from] EvaluationError),
#[error(transparent)]
#[diagnostic(transparent)]
PolicySet(#[from] PolicySetError),
#[error(transparent)]
#[diagnostic(transparent)]
Concretization(#[from] ConcretizationError),
}
#[doc(hidden)]
impl From<cedar_policy_core::authorizer::ReauthorizationError> for ReauthorizationError {
fn from(e: cedar_policy_core::authorizer::ReauthorizationError) -> Self {
match e {
cedar_policy_core::authorizer::ReauthorizationError::PolicySetError(err) => {
Self::PolicySet(err.into())
}
cedar_policy_core::authorizer::ReauthorizationError::ConcretizationError(err) => {
Self::Concretization(ConcretizationError(err))
}
}
}
}
#[derive(Debug, Error, Diagnostic)]
#[non_exhaustive]
pub enum ToCedarSchemaError {
#[error(transparent)]
#[diagnostic(transparent)]
NameCollisions(#[from] to_cedar_syntax_errors::NameCollisionsError),
}
pub mod to_cedar_syntax_errors {
use miette::Diagnostic;
use thiserror::Error;
#[derive(Debug, Error, Diagnostic)]
#[repr(transparent)]
#[error(transparent)]
pub struct NameCollisionsError(
pub(super) cedar_policy_validator::cedar_schema::fmt::NameCollisionsError,
);
impl NameCollisionsError {
pub fn names(&self) -> impl Iterator<Item = &str> {
self.0.names()
}
}
}
#[doc(hidden)]
impl From<cedar_policy_validator::cedar_schema::fmt::ToCedarSchemaSyntaxError>
for ToCedarSchemaError
{
fn from(value: cedar_policy_validator::cedar_schema::fmt::ToCedarSchemaSyntaxError) -> Self {
match value {
cedar_policy_validator::cedar_schema::fmt::ToCedarSchemaSyntaxError::NameCollisions(
name_collision_err,
) => NameCollisionsError(name_collision_err).into(),
}
}
}
pub mod cedar_schema_errors {
use miette::Diagnostic;
use thiserror::Error;
pub use cedar_policy_validator::CedarSchemaParseError as ParseError;
#[derive(Debug, Error, Diagnostic)]
#[error(transparent)]
pub struct IoError(#[from] pub(super) std::io::Error);
}
#[derive(Debug, Diagnostic, Error)]
#[non_exhaustive]
pub enum CedarSchemaError {
#[error(transparent)]
#[diagnostic(transparent)]
Parse(#[from] cedar_schema_errors::ParseError),
#[error(transparent)]
#[diagnostic(transparent)]
Io(#[from] cedar_schema_errors::IoError),
#[error(transparent)]
#[diagnostic(transparent)]
Schema(#[from] SchemaError),
}
#[doc(hidden)]
impl From<cedar_policy_validator::CedarSchemaError> for CedarSchemaError {
fn from(value: cedar_policy_validator::CedarSchemaError) -> Self {
match value {
cedar_policy_validator::CedarSchemaError::Schema(e) => e.into(),
cedar_policy_validator::CedarSchemaError::IO(e) => {
cedar_schema_errors::IoError(e).into()
}
cedar_policy_validator::CedarSchemaError::Parsing(e) => e.into(),
}
}
}
#[derive(Debug, Diagnostic, Error)]
#[error("in {} `{attr_or_tag}` of `{uid}`: {err}", if *.was_attr { "attribute" } else { "tag" })]
pub struct EntityAttrEvaluationError {
uid: EntityUid,
attr_or_tag: SmolStr,
was_attr: bool,
#[diagnostic(transparent)]
err: EvaluationError,
}
impl EntityAttrEvaluationError {
pub fn action(&self) -> &EntityUid {
&self.uid
}
pub fn attr(&self) -> &SmolStr {
&self.attr_or_tag
}
pub fn inner(&self) -> &EvaluationError {
&self.err
}
}
#[doc(hidden)]
impl From<ast::EntityAttrEvaluationError> for EntityAttrEvaluationError {
fn from(err: ast::EntityAttrEvaluationError) -> Self {
Self {
uid: err.uid.into(),
attr_or_tag: err.attr_or_tag,
was_attr: err.was_attr,
err: err.err,
}
}
}
#[derive(Debug, Diagnostic, Error)]
pub enum ContextCreationError {
#[error(transparent)]
#[diagnostic(transparent)]
NotARecord(context_creation_errors::NotARecord),
#[error(transparent)]
#[diagnostic(transparent)]
Evaluation(#[from] EvaluationError),
#[error(transparent)]
#[diagnostic(transparent)]
ExpressionConstruction(#[from] ExpressionConstructionError),
}
#[doc(hidden)]
impl From<ast::ContextCreationError> for ContextCreationError {
fn from(e: ast::ContextCreationError) -> Self {
match e {
ast::ContextCreationError::NotARecord(nre) => Self::NotARecord(nre),
ast::ContextCreationError::Evaluation(e) => Self::Evaluation(e),
ast::ContextCreationError::ExpressionConstruction(ece) => {
Self::ExpressionConstruction(ece)
}
}
}
}
mod context_creation_errors {
pub use cedar_policy_core::ast::context_creation_errors::NotARecord;
}
pub mod validation_errors;
#[derive(Debug, Clone, Error, Diagnostic)]
#[non_exhaustive]
pub enum ValidationError {
#[error(transparent)]
#[diagnostic(transparent)]
UnrecognizedEntityType(#[from] validation_errors::UnrecognizedEntityType),
#[error(transparent)]
#[diagnostic(transparent)]
UnrecognizedActionId(#[from] validation_errors::UnrecognizedActionId),
#[error(transparent)]
#[diagnostic(transparent)]
InvalidActionApplication(#[from] validation_errors::InvalidActionApplication),
#[error(transparent)]
#[diagnostic(transparent)]
UnexpectedType(#[from] validation_errors::UnexpectedType),
#[error(transparent)]
#[diagnostic(transparent)]
IncompatibleTypes(#[from] validation_errors::IncompatibleTypes),
#[error(transparent)]
#[diagnostic(transparent)]
UnsafeAttributeAccess(#[from] validation_errors::UnsafeAttributeAccess),
#[error(transparent)]
#[diagnostic(transparent)]
UnsafeOptionalAttributeAccess(#[from] validation_errors::UnsafeOptionalAttributeAccess),
#[error(transparent)]
#[diagnostic(transparent)]
UnsafeTagAccess(#[from] validation_errors::UnsafeTagAccess),
#[error(transparent)]
#[diagnostic(transparent)]
NoTagsAllowed(#[from] validation_errors::NoTagsAllowed),
#[error(transparent)]
#[diagnostic(transparent)]
UndefinedFunction(#[from] validation_errors::UndefinedFunction),
#[error(transparent)]
#[diagnostic(transparent)]
WrongNumberArguments(#[from] validation_errors::WrongNumberArguments),
#[diagnostic(transparent)]
#[error(transparent)]
FunctionArgumentValidation(#[from] validation_errors::FunctionArgumentValidation),
#[diagnostic(transparent)]
#[error(transparent)]
EmptySetForbidden(#[from] validation_errors::EmptySetForbidden),
#[diagnostic(transparent)]
#[error(transparent)]
NonLitExtConstructor(#[from] validation_errors::NonLitExtConstructor),
#[error(transparent)]
#[diagnostic(transparent)]
HierarchyNotRespected(#[from] validation_errors::HierarchyNotRespected),
#[error(transparent)]
#[diagnostic(transparent)]
InternalInvariantViolation(#[from] validation_errors::InternalInvariantViolation),
#[error(transparent)]
#[diagnostic(transparent)]
EntityDerefLevelViolation(#[from] validation_errors::EntityDerefLevelViolation),
}
impl ValidationError {
pub fn policy_id(&self) -> &crate::PolicyId {
match self {
Self::UnrecognizedEntityType(e) => e.policy_id(),
Self::UnrecognizedActionId(e) => e.policy_id(),
Self::InvalidActionApplication(e) => e.policy_id(),
Self::UnexpectedType(e) => e.policy_id(),
Self::IncompatibleTypes(e) => e.policy_id(),
Self::UnsafeAttributeAccess(e) => e.policy_id(),
Self::UnsafeOptionalAttributeAccess(e) => e.policy_id(),
Self::UnsafeTagAccess(e) => e.policy_id(),
Self::NoTagsAllowed(e) => e.policy_id(),
Self::UndefinedFunction(e) => e.policy_id(),
Self::WrongNumberArguments(e) => e.policy_id(),
Self::FunctionArgumentValidation(e) => e.policy_id(),
Self::EmptySetForbidden(e) => e.policy_id(),
Self::NonLitExtConstructor(e) => e.policy_id(),
Self::HierarchyNotRespected(e) => e.policy_id(),
Self::InternalInvariantViolation(e) => e.policy_id(),
Self::EntityDerefLevelViolation(e) => e.policy_id(),
}
}
}
#[doc(hidden)]
impl From<cedar_policy_validator::ValidationError> for ValidationError {
fn from(error: cedar_policy_validator::ValidationError) -> Self {
match error {
cedar_policy_validator::ValidationError::UnrecognizedEntityType(e) => {
Self::UnrecognizedEntityType(e.into())
}
cedar_policy_validator::ValidationError::UnrecognizedActionId(e) => {
Self::UnrecognizedActionId(e.into())
}
cedar_policy_validator::ValidationError::InvalidActionApplication(e) => {
Self::InvalidActionApplication(e.into())
}
cedar_policy_validator::ValidationError::UnexpectedType(e) => {
Self::UnexpectedType(e.into())
}
cedar_policy_validator::ValidationError::IncompatibleTypes(e) => {
Self::IncompatibleTypes(e.into())
}
cedar_policy_validator::ValidationError::UnsafeAttributeAccess(e) => {
Self::UnsafeAttributeAccess(e.into())
}
cedar_policy_validator::ValidationError::UnsafeOptionalAttributeAccess(e) => {
Self::UnsafeOptionalAttributeAccess(e.into())
}
cedar_policy_validator::ValidationError::UnsafeTagAccess(e) => {
Self::UnsafeTagAccess(e.into())
}
cedar_policy_validator::ValidationError::NoTagsAllowed(e) => {
Self::NoTagsAllowed(e.into())
}
cedar_policy_validator::ValidationError::UndefinedFunction(e) => {
Self::UndefinedFunction(e.into())
}
cedar_policy_validator::ValidationError::WrongNumberArguments(e) => {
Self::WrongNumberArguments(e.into())
}
cedar_policy_validator::ValidationError::FunctionArgumentValidation(e) => {
Self::FunctionArgumentValidation(e.into())
}
cedar_policy_validator::ValidationError::EmptySetForbidden(e) => {
Self::EmptySetForbidden(e.into())
}
cedar_policy_validator::ValidationError::NonLitExtConstructor(e) => {
Self::NonLitExtConstructor(e.into())
}
cedar_policy_validator::ValidationError::HierarchyNotRespected(e) => {
Self::HierarchyNotRespected(e.into())
}
cedar_policy_validator::ValidationError::InternalInvariantViolation(e) => {
Self::InternalInvariantViolation(e.into())
}
#[cfg(feature = "level-validate")]
cedar_policy_validator::ValidationError::EntityDerefLevelViolation(e) => {
Self::EntityDerefLevelViolation(e.into())
}
}
}
}
pub mod validation_warnings;
#[derive(Debug, Clone, Error, Diagnostic)]
#[non_exhaustive]
pub enum ValidationWarning {
#[diagnostic(transparent)]
#[error(transparent)]
MixedScriptString(#[from] validation_warnings::MixedScriptString),
#[diagnostic(transparent)]
#[error(transparent)]
BidiCharsInString(#[from] validation_warnings::BidiCharsInString),
#[diagnostic(transparent)]
#[error(transparent)]
BidiCharsInIdentifier(#[from] validation_warnings::BidiCharsInIdentifier),
#[diagnostic(transparent)]
#[error(transparent)]
MixedScriptIdentifier(#[from] validation_warnings::MixedScriptIdentifier),
#[diagnostic(transparent)]
#[error(transparent)]
ConfusableIdentifier(#[from] validation_warnings::ConfusableIdentifier),
#[diagnostic(transparent)]
#[error(transparent)]
ImpossiblePolicy(#[from] validation_warnings::ImpossiblePolicy),
}
impl ValidationWarning {
pub fn policy_id(&self) -> &PolicyId {
match self {
Self::MixedScriptString(w) => w.policy_id(),
Self::BidiCharsInString(w) => w.policy_id(),
Self::BidiCharsInIdentifier(w) => w.policy_id(),
Self::MixedScriptIdentifier(w) => w.policy_id(),
Self::ConfusableIdentifier(w) => w.policy_id(),
Self::ImpossiblePolicy(w) => w.policy_id(),
}
}
}
#[doc(hidden)]
impl From<cedar_policy_validator::ValidationWarning> for ValidationWarning {
fn from(warning: cedar_policy_validator::ValidationWarning) -> Self {
match warning {
cedar_policy_validator::ValidationWarning::MixedScriptString(w) => {
Self::MixedScriptString(w.into())
}
cedar_policy_validator::ValidationWarning::BidiCharsInString(w) => {
Self::BidiCharsInString(w.into())
}
cedar_policy_validator::ValidationWarning::BidiCharsInIdentifier(w) => {
Self::BidiCharsInIdentifier(w.into())
}
cedar_policy_validator::ValidationWarning::MixedScriptIdentifier(w) => {
Self::MixedScriptIdentifier(w.into())
}
cedar_policy_validator::ValidationWarning::ConfusableIdentifier(w) => {
Self::ConfusableIdentifier(w.into())
}
cedar_policy_validator::ValidationWarning::ImpossiblePolicy(w) => {
Self::ImpossiblePolicy(w.into())
}
}
}
}
pub mod policy_set_errors {
use super::Error;
use crate::PolicyId;
use cedar_policy_core::ast;
use miette::Diagnostic;
#[derive(Debug, Diagnostic, Error)]
#[error("duplicate template or policy id `{id}`")]
pub struct AlreadyDefined {
pub(crate) id: PolicyId,
}
impl AlreadyDefined {
pub fn duplicate_id(&self) -> &PolicyId {
&self.id
}
}
#[derive(Debug, Diagnostic, Error)]
#[error("unable to link template")]
pub struct LinkingError {
#[from]
#[diagnostic(transparent)]
pub(crate) inner: ast::LinkingError,
}
#[derive(Debug, Diagnostic, Error)]
#[error("expected a static policy, but a template-linked policy was provided")]
pub struct ExpectedStatic {
_dummy: (),
}
impl ExpectedStatic {
pub(crate) fn new() -> Self {
Self { _dummy: () }
}
}
#[derive(Debug, Diagnostic, Error)]
#[error("expected a template, but a static policy was provided")]
pub struct ExpectedTemplate {
_dummy: (),
}
impl ExpectedTemplate {
pub(crate) fn new() -> Self {
Self { _dummy: () }
}
}
#[derive(Debug, Diagnostic, Error)]
#[error("unable to remove static policy `{policy_id}` because it does not exist")]
pub struct PolicyNonexistentError {
pub(crate) policy_id: PolicyId,
}
impl PolicyNonexistentError {
pub fn policy_id(&self) -> &PolicyId {
&self.policy_id
}
}
#[derive(Debug, Diagnostic, Error)]
#[error("unable to remove template `{template_id}` because it does not exist")]
pub struct TemplateNonexistentError {
pub(crate) template_id: PolicyId,
}
impl TemplateNonexistentError {
pub fn template_id(&self) -> &PolicyId {
&self.template_id
}
}
#[derive(Debug, Diagnostic, Error)]
#[error("unable to remove policy template `{template_id}` because it has active links")]
pub struct RemoveTemplateWithActiveLinksError {
pub(crate) template_id: PolicyId,
}
impl RemoveTemplateWithActiveLinksError {
pub fn template_id(&self) -> &PolicyId {
&self.template_id
}
}
#[derive(Debug, Diagnostic, Error)]
#[error("unable to remove policy template `{template_id}` because it is not a template")]
pub struct RemoveTemplateNotTemplateError {
pub(crate) template_id: PolicyId,
}
impl RemoveTemplateNotTemplateError {
pub fn template_id(&self) -> &PolicyId {
&self.template_id
}
}
#[derive(Debug, Diagnostic, Error)]
#[error("unable to unlink policy `{policy_id}` because it does not exist")]
pub struct LinkNonexistentError {
pub(crate) policy_id: PolicyId,
}
impl LinkNonexistentError {
pub fn policy_id(&self) -> &PolicyId {
&self.policy_id
}
}
#[derive(Debug, Diagnostic, Error)]
#[error("unable to unlink `{policy_id}` because it is not a link")]
pub struct UnlinkLinkNotLinkError {
pub(crate) policy_id: PolicyId,
}
impl UnlinkLinkNotLinkError {
pub fn policy_id(&self) -> &PolicyId {
&self.policy_id
}
}
#[derive(Debug, Diagnostic, Error)]
#[error("error serializing/deserializing policy set to/from JSON")]
pub struct JsonPolicySetError {
#[from]
pub(crate) inner: serde_json::Error,
}
}
#[derive(Debug, Diagnostic, Error)]
#[non_exhaustive]
pub enum PolicySetError {
#[error(transparent)]
#[diagnostic(transparent)]
AlreadyDefined(#[from] policy_set_errors::AlreadyDefined),
#[error(transparent)]
#[diagnostic(transparent)]
Linking(#[from] policy_set_errors::LinkingError),
#[error(transparent)]
#[diagnostic(transparent)]
ExpectedStatic(#[from] policy_set_errors::ExpectedStatic),
#[error(transparent)]
#[diagnostic(transparent)]
ExpectedTemplate(#[from] policy_set_errors::ExpectedTemplate),
#[error(transparent)]
#[diagnostic(transparent)]
PolicyNonexistent(#[from] policy_set_errors::PolicyNonexistentError),
#[error(transparent)]
#[diagnostic(transparent)]
TemplateNonexistent(#[from] policy_set_errors::TemplateNonexistentError),
#[error(transparent)]
#[diagnostic(transparent)]
RemoveTemplateWithActiveLinks(#[from] policy_set_errors::RemoveTemplateWithActiveLinksError),
#[error(transparent)]
#[diagnostic(transparent)]
RemoveTemplateNotTemplate(#[from] policy_set_errors::RemoveTemplateNotTemplateError),
#[error(transparent)]
#[diagnostic(transparent)]
LinkNonexistent(#[from] policy_set_errors::LinkNonexistentError),
#[error(transparent)]
#[diagnostic(transparent)]
UnlinkLinkNotLink(#[from] policy_set_errors::UnlinkLinkNotLinkError),
#[error(transparent)]
#[diagnostic(transparent)]
FromJson(#[from] PolicyFromJsonError),
#[error("Error serializing a policy/template to JSON")]
#[diagnostic(transparent)]
ToJson(#[from] PolicyToJsonError),
#[error(transparent)]
#[diagnostic(transparent)]
JsonPolicySet(#[from] policy_set_errors::JsonPolicySetError),
}
#[doc(hidden)]
impl From<ast::PolicySetError> for PolicySetError {
fn from(e: ast::PolicySetError) -> Self {
match e {
ast::PolicySetError::Occupied { id } => {
Self::AlreadyDefined(policy_set_errors::AlreadyDefined {
id: PolicyId::new(id),
})
}
}
}
}
#[doc(hidden)]
impl From<ast::LinkingError> for PolicySetError {
fn from(e: ast::LinkingError) -> Self {
Self::Linking(e.into())
}
}
#[doc(hidden)]
impl From<ast::UnexpectedSlotError> for PolicySetError {
fn from(_: ast::UnexpectedSlotError) -> Self {
Self::ExpectedStatic(policy_set_errors::ExpectedStatic::new())
}
}
#[doc(hidden)]
impl From<est::PolicySetFromJsonError> for PolicySetError {
fn from(e: est::PolicySetFromJsonError) -> Self {
match e {
est::PolicySetFromJsonError::PolicySet(e) => e.into(),
est::PolicySetFromJsonError::Linking(e) => e.into(),
est::PolicySetFromJsonError::FromJsonError(e) => Self::FromJson(e.into()),
}
}
}
#[derive(Debug, Diagnostic, Error)]
#[error(transparent)]
#[diagnostic(transparent)]
pub struct ParseErrors(#[from] cedar_policy_core::parser::err::ParseErrors);
impl ParseErrors {
pub fn iter(&self) -> impl Iterator<Item = &ParseError> {
self.0.iter().map(ParseError::ref_cast)
}
}
#[derive(Debug, Diagnostic, Error, RefCast)]
#[repr(transparent)]
#[error(transparent)]
#[diagnostic(transparent)]
#[non_exhaustive]
pub struct ParseError {
#[from]
inner: cedar_policy_core::parser::err::ParseError,
}
#[derive(Debug, Diagnostic, Error)]
pub enum PolicyToJsonError {
#[error(transparent)]
#[diagnostic(transparent)]
Parse(#[from] ParseErrors),
#[error(transparent)]
#[diagnostic(transparent)]
Link(#[from] policy_to_json_errors::JsonLinkError),
#[error(transparent)]
JsonSerialization(#[from] policy_to_json_errors::PolicyJsonSerializationError),
}
#[doc(hidden)]
impl From<est::LinkingError> for PolicyToJsonError {
fn from(e: est::LinkingError) -> Self {
policy_to_json_errors::JsonLinkError::from(e).into()
}
}
impl From<serde_json::Error> for PolicyToJsonError {
fn from(e: serde_json::Error) -> Self {
policy_to_json_errors::PolicyJsonSerializationError::from(e).into()
}
}
pub mod policy_to_json_errors {
use cedar_policy_core::est;
use miette::Diagnostic;
use thiserror::Error;
#[derive(Debug, Diagnostic, Error)]
#[error(transparent)]
#[diagnostic(transparent)]
pub struct JsonLinkError {
#[from]
err: est::LinkingError,
}
#[derive(Debug, Diagnostic, Error)]
#[error(transparent)]
pub struct PolicyJsonSerializationError {
#[from]
err: serde_json::Error,
}
}
#[derive(Debug, Diagnostic, Error)]
#[error("error deserializing a policy/template from JSON")]
#[diagnostic(transparent)]
pub struct PolicyFromJsonError {
#[from]
pub(crate) inner: cedar_policy_core::est::FromJsonError,
}
#[derive(Debug, Diagnostic, Error)]
pub enum ContextJsonError {
#[error(transparent)]
#[diagnostic(transparent)]
JsonDeserialization(#[from] entities_json_errors::JsonDeserializationError),
#[error(transparent)]
#[diagnostic(transparent)]
ContextCreation(#[from] ContextCreationError),
#[error(transparent)]
#[diagnostic(transparent)]
MissingAction(#[from] context_json_errors::MissingActionError),
}
impl ContextJsonError {
pub(crate) fn missing_action(action: EntityUid) -> Self {
Self::MissingAction(context_json_errors::MissingActionError { action })
}
}
#[doc(hidden)]
impl From<cedar_policy_core::entities::json::ContextJsonDeserializationError> for ContextJsonError {
fn from(e: cedar_policy_core::entities::json::ContextJsonDeserializationError) -> Self {
match e {
cedar_policy_core::entities::json::ContextJsonDeserializationError::JsonDeserialization(e) => Self::JsonDeserialization(e),
cedar_policy_core::entities::json::ContextJsonDeserializationError::ContextCreation(e) => Self::ContextCreation(e.into())
}
}
}
pub mod context_json_errors {
use super::EntityUid;
use miette::Diagnostic;
use thiserror::Error;
#[derive(Debug, Diagnostic, Error)]
#[error("action `{action}` does not exist in the supplied schema")]
pub struct MissingActionError {
pub(super) action: EntityUid,
}
impl MissingActionError {
pub fn action(&self) -> &EntityUid {
&self.action
}
}
}
#[derive(Debug, Diagnostic, Error)]
#[non_exhaustive]
pub enum RestrictedExpressionParseError {
#[error(transparent)]
#[diagnostic(transparent)]
Parse(#[from] ParseErrors),
#[error(transparent)]
#[diagnostic(transparent)]
InvalidRestrictedExpression(#[from] RestrictedExpressionError),
}
#[doc(hidden)]
impl From<cedar_policy_core::ast::RestrictedExpressionParseError>
for RestrictedExpressionParseError
{
fn from(e: cedar_policy_core::ast::RestrictedExpressionParseError) -> Self {
match e {
cedar_policy_core::ast::RestrictedExpressionParseError::Parse(e) => {
Self::Parse(e.into())
}
cedar_policy_core::ast::RestrictedExpressionParseError::InvalidRestrictedExpression(
e,
) => e.into(),
}
}
}
#[derive(Debug, Diagnostic, Error)]
#[non_exhaustive]
pub enum RequestValidationError {
#[error(transparent)]
#[diagnostic(transparent)]
UndeclaredAction(#[from] request_validation_errors::UndeclaredActionError),
#[error(transparent)]
#[diagnostic(transparent)]
UndeclaredPrincipalType(#[from] request_validation_errors::UndeclaredPrincipalTypeError),
#[error(transparent)]
#[diagnostic(transparent)]
UndeclaredResourceType(#[from] request_validation_errors::UndeclaredResourceTypeError),
#[error(transparent)]
#[diagnostic(transparent)]
InvalidPrincipalType(#[from] request_validation_errors::InvalidPrincipalTypeError),
#[error(transparent)]
#[diagnostic(transparent)]
InvalidResourceType(#[from] request_validation_errors::InvalidResourceTypeError),
#[error(transparent)]
#[diagnostic(transparent)]
InvalidContext(#[from] request_validation_errors::InvalidContextError),
#[error(transparent)]
#[diagnostic(transparent)]
TypeOfContext(#[from] request_validation_errors::TypeOfContextError),
}
#[doc(hidden)]
impl From<cedar_policy_validator::RequestValidationError> for RequestValidationError {
fn from(e: cedar_policy_validator::RequestValidationError) -> Self {
match e {
cedar_policy_validator::RequestValidationError::UndeclaredAction(e) => {
Self::UndeclaredAction(e.into())
}
cedar_policy_validator::RequestValidationError::UndeclaredPrincipalType(e) => {
Self::UndeclaredPrincipalType(e.into())
}
cedar_policy_validator::RequestValidationError::UndeclaredResourceType(e) => {
Self::UndeclaredResourceType(e.into())
}
cedar_policy_validator::RequestValidationError::InvalidPrincipalType(e) => {
Self::InvalidPrincipalType(e.into())
}
cedar_policy_validator::RequestValidationError::InvalidResourceType(e) => {
Self::InvalidResourceType(e.into())
}
cedar_policy_validator::RequestValidationError::InvalidContext(e) => {
Self::InvalidContext(e.into())
}
cedar_policy_validator::RequestValidationError::TypeOfContext(e) => {
Self::TypeOfContext(e.into())
}
}
}
}
pub mod request_validation_errors {
use cedar_policy_core::extensions::ExtensionFunctionLookupError;
use miette::Diagnostic;
use ref_cast::RefCast;
use thiserror::Error;
use crate::{Context, EntityTypeName, EntityUid};
#[derive(Debug, Diagnostic, Error)]
#[error(transparent)]
#[diagnostic(transparent)]
pub struct UndeclaredActionError(
#[from] cedar_policy_validator::request_validation_errors::UndeclaredActionError,
);
impl UndeclaredActionError {
pub fn action(&self) -> &EntityUid {
RefCast::ref_cast(self.0.action())
}
}
#[derive(Debug, Diagnostic, Error)]
#[error(transparent)]
#[diagnostic(transparent)]
pub struct UndeclaredPrincipalTypeError(
#[from] cedar_policy_validator::request_validation_errors::UndeclaredPrincipalTypeError,
);
impl UndeclaredPrincipalTypeError {
pub fn principal_ty(&self) -> &EntityTypeName {
RefCast::ref_cast(self.0.principal_ty())
}
}
#[derive(Debug, Diagnostic, Error)]
#[error(transparent)]
#[diagnostic(transparent)]
pub struct UndeclaredResourceTypeError(
#[from] cedar_policy_validator::request_validation_errors::UndeclaredResourceTypeError,
);
impl UndeclaredResourceTypeError {
pub fn resource_ty(&self) -> &EntityTypeName {
RefCast::ref_cast(self.0.resource_ty())
}
}
#[derive(Debug, Diagnostic, Error)]
#[error(transparent)]
#[diagnostic(transparent)]
pub struct InvalidPrincipalTypeError(
#[from] cedar_policy_validator::request_validation_errors::InvalidPrincipalTypeError,
);
impl InvalidPrincipalTypeError {
pub fn principal_ty(&self) -> &EntityTypeName {
RefCast::ref_cast(self.0.principal_ty())
}
pub fn action(&self) -> &EntityUid {
RefCast::ref_cast(self.0.action())
}
}
#[derive(Debug, Diagnostic, Error)]
#[error(transparent)]
#[diagnostic(transparent)]
pub struct InvalidResourceTypeError(
#[from] cedar_policy_validator::request_validation_errors::InvalidResourceTypeError,
);
impl InvalidResourceTypeError {
pub fn resource_ty(&self) -> &EntityTypeName {
RefCast::ref_cast(self.0.resource_ty())
}
pub fn action(&self) -> &EntityUid {
RefCast::ref_cast(self.0.action())
}
}
#[derive(Debug, Diagnostic, Error)]
#[error(transparent)]
#[diagnostic(transparent)]
pub struct InvalidContextError(
#[from] cedar_policy_validator::request_validation_errors::InvalidContextError,
);
impl InvalidContextError {
pub fn context(&self) -> &Context {
RefCast::ref_cast(self.0.context())
}
pub fn action(&self) -> &EntityUid {
RefCast::ref_cast(self.0.action())
}
}
#[derive(Debug, Diagnostic, Error)]
#[error(transparent)]
#[diagnostic(transparent)]
pub struct TypeOfContextError(#[from] ExtensionFunctionLookupError);
}
#[derive(Debug, Error, Diagnostic)]
#[non_exhaustive]
#[cfg(feature = "entity-manifest")]
pub enum EntityManifestError {
#[error(transparent)]
#[diagnostic(transparent)]
Validation(#[from] ValidationResult),
#[error(transparent)]
#[diagnostic(transparent)]
Entities(#[from] EntitiesError),
#[error(transparent)]
#[diagnostic(transparent)]
PartialRequest(#[from] PartialRequestError),
#[error(transparent)]
#[diagnostic(transparent)]
PartialExpression(#[from] PartialExpressionError),
#[error(transparent)]
#[diagnostic(transparent)]
FailedAnalysis(#[from] FailedAnalysisError),
}
#[cfg(feature = "entity-manifest")]
impl From<entity_manifest::EntityManifestError> for EntityManifestError {
fn from(e: entity_manifest::EntityManifestError) -> Self {
match e {
entity_manifest::EntityManifestError::Validation(e) => Self::Validation(e.into()),
entity_manifest::EntityManifestError::Entities(e) => Self::Entities(e),
entity_manifest::EntityManifestError::PartialRequest(e) => Self::PartialRequest(e),
entity_manifest::EntityManifestError::PartialExpression(e) => {
Self::PartialExpression(e)
}
entity_manifest::EntityManifestError::FailedAnalysis(e) => Self::FailedAnalysis(e),
}
}
}