Skip to content

Conversation

khieta
Copy link
Contributor

@khieta khieta commented Jun 11, 2024

Description of changes

This PR addresses #745 for ParseErrors by exposing the bare minimum level of detail: users can use the miette::Diagnotic attached to ParseErrors, or use .iter() to get an iterator over individual ParseErrors. Each ParseError will expose no internal information outside of its miette::Diagnostic.

I think the ideal solution here is to flatten the structure of ParseError to remove the distinction between CST and AST errors and get rid of the "Kind" pattern, similar to what has been done for the validation & evaluation errors... but this is a large amount of work for small benefit (I find it unlikely that users will need to programmatically match against parse errors). Assuming this PR is approved, I'll make a backlog issue for the larger change. Note that this larger change can be made in a backwards-compatible way in the future.

Issue #, if available

Checklist for requesting a review

The change in this PR is (choose one, and delete the other options):

  • A breaking change requiring a major version bump to cedar-policy (e.g., changes to the signature of an existing API).

(Part of the batch of breaking error structure changes for 4.0)

I confirm that this PR (choose one, and delete the other options):

  • Updates the "Unreleased" section of the CHANGELOG with a description of my change (required for major/minor version bumps).

(Adds an undocumented breaking change made in #908.)

I confirm that cedar-spec (choose one, and delete the other options):

  • Does not require updates because my change does not impact the Cedar formal model or DRT infrastructure.

@khieta khieta requested a review from cdisselkoen June 11, 2024 14:39
Copy link
Contributor

@john-h-kastner-aws john-h-kastner-aws left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

#[repr(transparent)]
#[error(transparent)]
#[diagnostic(transparent)]
pub struct ParseError(#[from] cedar_policy_core::parser::err::ParseError);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding exposing ParseError as an enum in the future, we should fine based on https://predr.ag/blog/turning-rust-struct-to-enum-is-not-always-breaking/ (by the author of cargo-semver-checks, so I assume they know what they're talking about)

Comment on lines +752 to +753
/// Marked as `non_exhaustive` to support adding additional error information
/// in the future without a major version bump.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we technically need non_exhaustive for that, since the fields are already private, but it doesn't hurt

@khieta khieta merged commit b5ac528 into main Jun 14, 2024
@khieta khieta deleted the khieta/cedar-745 branch June 14, 2024 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants