cedar_policy_core::parser::err

Enum ToASTErrorKind

Source
#[non_exhaustive]
pub enum ToASTErrorKind {
Show 55 variants DuplicateTemplateId(PolicyID), DuplicatePolicyId(PolicyID), ExpectedStaticPolicy(ExpectedStaticPolicy), ExpectedTemplate(ExpectedTemplate), DuplicateAnnotation(AnyId), SlotsInConditionClause(SlotsInConditionClause), MissingScopeVariable(Var), ExtraScopeElement(VariableDef), ReservedIdentifier(Ident), InvalidIdentifier(String), InvalidSingleEq, InvalidEffect(Ident), InvalidCondition(Ident), InvalidScopeVariable(Ident), IncorrectVariable { expected: Var, got: Var, }, InvalidScopeOperator(RelOp), InvalidActionScopeOperator(RelOp), IsInActionScope, IsWithEq, InvalidActionType(InvalidActionType), EmptyClause(Option<Ident>), MembershipInvariantViolation, InvalidString(String), ArbitraryVariable(SmolStr), InvalidAttribute(SmolStr), PathAsAttribute(String), FunctionCallOnMethod(UnreservedId), MethodCallOnFunction(UnreservedId), InvalidPattern(String), InvalidIsType(String), WrongNode { expected: &'static str, got: String, suggestion: Option<String>, }, AmbiguousOperators, UnsupportedDivision, UnsupportedModulo, ExpressionConstructionError(ExpressionConstructionError), IntegerLiteralTooLarge(u64), UnaryOpLimit(UnaryOp), VariableCall(Var), NoMethods(Name, UnreservedId), UnknownMethod { id: UnreservedId, hint: Option<String>, }, UnknownFunction { id: Name, hint: Option<String>, }, InvalidEntityLiteral(String), ExpressionCall, InvalidAccess(Name, SmolStr), InvalidIndex(Name, SmolStr), NonStringIndex, TypeConstraints, NonNormalizedString { kind: &'static str, src: String, normalized_src: String, }, EmptyNodeInvariantViolation, WrongArity { name: &'static str, expected: usize, got: usize, }, Unescape(UnescapeError), WrongEntityArgument(WrongEntityArgument), InvalidSlot(SmolStr), ReservedNamespace(ReservedNameError), InvertedIsIn,
}
Expand description

Details about a particular kind of ToASTError.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

DuplicateTemplateId(PolicyID)

Returned when we attempt to parse a template with a conflicting id

§

DuplicatePolicyId(PolicyID)

Returned when we attempt to parse a policy with a conflicting id

§

ExpectedStaticPolicy(ExpectedStaticPolicy)

Returned when a template is encountered but a static policy is expected

§

ExpectedTemplate(ExpectedTemplate)

Returned when a static policy is encountered but a template is expected

§

DuplicateAnnotation(AnyId)

Returned when we attempt to parse a policy or template with duplicate or conflicting annotations

§

SlotsInConditionClause(SlotsInConditionClause)

Returned when a policy contains template slots in a when/unless clause. This is not currently supported; see RFC 3.

§

MissingScopeVariable(Var)

Returned when a policy is missing one of the three required scope elements (principal, action, and resource)

§

ExtraScopeElement(VariableDef)

Returned when a policy has an extra scope element

§

ReservedIdentifier(Ident)

Returned when a policy uses a reserved keyword as an identifier.

§

InvalidIdentifier(String)

Returned when a policy contains an invalid identifier. This error is not currently returned, but is here for future-proofing; see cst::Ident::Invalid.

§

InvalidSingleEq

Returned when a policy uses ‘=’ as a binary operator. ‘=’ is not an operator in Cedar; we can suggest ‘==’ instead.

§

InvalidEffect(Ident)

Returned when a policy uses an effect keyword beyond permit or forbid

§

InvalidCondition(Ident)

Returned when a policy uses a condition keyword beyond when or unless

§

InvalidScopeVariable(Ident)

Returned when a policy uses a variable in the scope beyond principal, action, or resource

§

IncorrectVariable

Returned when a policy scope clause contains the wrong variable. (principal must be in the first clause, etc…)

Fields

§expected: Var

The variable that is expected

§got: Var

The variable that was present

§

InvalidScopeOperator(RelOp)

Returned when a policy scope uses an operator not allowed in scopes

§

InvalidActionScopeOperator(RelOp)

Returned when an action scope uses an operator not allowed in action scopes (special case of InvalidScopeOperator)

§

IsInActionScope

Returned when the action scope clause contains an is

§

IsWithEq

Returned when an is operator is used together with ==

§

InvalidActionType(InvalidActionType)

Returned when an entity uid used as an action does not have the type Action

§

EmptyClause(Option<Ident>)

Returned when a condition clause is empty

§

MembershipInvariantViolation

Returned when membership chains do not resolve to an expression, violating an internal invariant

§

InvalidString(String)

Returned for a non-parse-able string literal

§

ArbitraryVariable(SmolStr)

Returned when attempting to use an arbitrary variable name. Cedar does not support arbitrary variables.

§

InvalidAttribute(SmolStr)

Returned when attempting to use an invalid attribute name

§

PathAsAttribute(String)

Returned when attempting to use an attribute with a namespace

§

FunctionCallOnMethod(UnreservedId)

Returned when a policy attempts to call a method function-style

§

MethodCallOnFunction(UnreservedId)

Returned when a policy attempts to call a function in the method style

§

InvalidPattern(String)

Returned when the right hand side of a like expression is not a constant pattern literal

§

InvalidIsType(String)

Returned when the right hand side of a is expression is not an entity type name

§

WrongNode

Returned when an unexpected node is in the policy scope

Fields

§expected: &'static str

What the expected AST node kind was

§got: String

What AST node was present in the policy source

§suggestion: Option<String>

Optional free-form text with a suggestion for how to fix the problem

§

AmbiguousOperators

Returned when a policy contains ambiguous ordering of operators. This can be resolved by using parenthesis to make order explicit

§

UnsupportedDivision

Returned when a policy uses the division operator (/), which is not supported

§

UnsupportedModulo

Returned when a policy uses the remainder/modulo operator (%), which is not supported

§

ExpressionConstructionError(ExpressionConstructionError)

Any ExpressionConstructionError can also happen while converting CST to AST

§

IntegerLiteralTooLarge(u64)

Returned when a policy contains an integer literal that is out of range

§

UnaryOpLimit(UnaryOp)

Returned when a unary operator is chained more than 4 times in a row

§

VariableCall(Var)

Returned when a variable is called as a function, which is not allowed. Functions are not first class values in Cedar

§

NoMethods(Name, UnreservedId)

Returned when a policy attempts to call a method on a value that has no methods

§

UnknownMethod

Returned when a policy attempts to call a method that does not exist

Fields

§id: UnreservedId

The user-provided method id

§hint: Option<String>

The hint to resolve the error

§

UnknownFunction

Returned when a policy attempts to call a function that does not exist

Fields

§id: Name

The user-provided function id

§hint: Option<String>

The hint to resolve the error

§

InvalidEntityLiteral(String)

Returned when a policy attempts to write an entity literal

§

ExpressionCall

Returned when an expression is the target of a function call. Functions are not first class values in Cedar

§

InvalidAccess(Name, SmolStr)

Returned when a policy attempts to access the fields of a value with no fields

§

InvalidIndex(Name, SmolStr)

Returned when a policy attempts to index on a fields of a value with no fields

§

NonStringIndex

Returned when the contents of an indexing expression is not a string literal

§

TypeConstraints

Returned when a user attempts to use type-constraint : syntax. This syntax was not adopted, but is can be used to write type constraints in the policy scope.

§

NonNormalizedString

Returned when a string needs to be fully normalized

Fields

§kind: &'static str

The kind of string we are expecting

§src: String

The source string passed in

§normalized_src: String

The normalized form of the string

§

EmptyNodeInvariantViolation

Returned when a CST node is empty during CST to AST/EST conversion. This should have resulted in an error during the text to CST conversion, which will terminate parsing. So it should be unreachable in later stages.

§

WrongArity

Returned when a function or method is called with the wrong arity

Fields

§name: &'static str

Name of the function or method being called

§expected: usize

The expected number of arguments

§got: usize

The number of arguments present in source

§

Unescape(UnescapeError)

Returned when a string contains invalid escapes

§

WrongEntityArgument(WrongEntityArgument)

Returned when a policy scope has incorrect entity uids or template slots

§

InvalidSlot(SmolStr)

Returned when a policy contains a template slot other than ?principal or ?resource

§

ReservedNamespace(ReservedNameError)

Returned when an entity type contains a reserved namespace or typename (as of this writing, just __cedar)

§

InvertedIsIn

Returned when a policy uses _ in _ is _ instead of _ is _ in _ in the policy scope

Implementations§

Source§

impl ToASTErrorKind

Source

pub fn wrong_node( expected: &'static str, got: impl Into<String>, suggestion: Option<impl Into<String>>, ) -> Self

Constructor for the ToASTErrorKind::WrongNode error

Source

pub fn wrong_arity(name: &'static str, expected: usize, got: usize) -> Self

Constructor for the ToASTErrorKind::WrongArity error

Source

pub fn slots_in_condition_clause(slot: Slot, clause_type: &'static str) -> Self

Constructor for the ToASTErrorKind::SlotsInConditionClause error

Source

pub fn expected_static_policy(slot: Slot) -> Self

Constructor for the ToASTErrorKind::ExpectedStaticPolicy error

Source

pub fn expected_template() -> Self

Constructor for the ToASTErrorKind::ExpectedTemplate error

Source

pub fn wrong_entity_argument_one_expected(expected: Ref, got: Ref) -> Self

Constructor for the ToASTErrorKind::WrongEntityArgument error when one kind of entity argument was expected

Source

pub fn wrong_entity_argument_two_expected(r1: Ref, r2: Ref, got: Ref) -> Self

Constructor for the ToASTErrorKind::WrongEntityArgument error when one of two kinds of entity argument was expected

Trait Implementations§

Source§

impl Clone for ToASTErrorKind

Source§

fn clone(&self) -> ToASTErrorKind

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ToASTErrorKind

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Diagnostic for ToASTErrorKind

Source§

fn code(&self) -> Option<Box<dyn Display + '_>>

Unique diagnostic code that can be used to look up more information about this Diagnostic. Ideally also globally unique, and documented in the toplevel crate’s documentation for easy searching. Rust path format (foo::bar::baz) is recommended, but more classic codes like E0123 or enums will work just fine.
Source§

fn help(&self) -> Option<Box<dyn Display + '_>>

Additional help text related to this Diagnostic. Do you have any advice for the poor soul who’s just run into this issue?
Source§

fn severity(&self) -> Option<Severity>

Diagnostic severity. This may be used by ReportHandlers to change the display format of this diagnostic. Read more
Source§

fn labels(&self) -> Option<Box<dyn Iterator<Item = LabeledSpan> + '_>>

Labels to apply to this Diagnostic’s Diagnostic::source_code
Source§

fn source_code(&self) -> Option<&dyn SourceCode>

Source code to apply this Diagnostic’s Diagnostic::labels to.
Source§

fn related(&self) -> Option<Box<dyn Iterator<Item = &dyn Diagnostic> + '_>>

Additional related Diagnostics.
Source§

fn url(&self) -> Option<Box<dyn Display + '_>>

URL to visit for a more detailed explanation/help about this Diagnostic.
Source§

fn diagnostic_source(&self) -> Option<&dyn Diagnostic>

The cause of the error.
Source§

impl Display for ToASTErrorKind

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for ToASTErrorKind

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<ExpectedStaticPolicy> for ToASTErrorKind

Source§

fn from(source: ExpectedStaticPolicy) -> Self

Converts to this type from the input type.
Source§

impl From<ExpectedTemplate> for ToASTErrorKind

Source§

fn from(source: ExpectedTemplate) -> Self

Converts to this type from the input type.
Source§

impl From<ExpressionConstructionError> for ToASTErrorKind

Source§

fn from(source: ExpressionConstructionError) -> Self

Converts to this type from the input type.
Source§

impl From<InvalidActionType> for ToASTErrorKind

Source§

fn from(source: InvalidActionType) -> Self

Converts to this type from the input type.
Source§

impl From<ReservedNameError> for ToASTErrorKind

Source§

fn from(source: ReservedNameError) -> Self

Converts to this type from the input type.
Source§

impl From<SlotsInConditionClause> for ToASTErrorKind

Source§

fn from(source: SlotsInConditionClause) -> Self

Converts to this type from the input type.
Source§

impl From<UnescapeError> for ToASTErrorKind

Source§

fn from(source: UnescapeError) -> Self

Converts to this type from the input type.
Source§

impl From<WrongEntityArgument> for ToASTErrorKind

Source§

fn from(source: WrongEntityArgument) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for ToASTErrorKind

Source§

fn eq(&self, other: &ToASTErrorKind) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for ToASTErrorKind

Source§

impl StructuralPartialEq for ToASTErrorKind

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToSmolStr for T
where T: Display + ?Sized,

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.