Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement #745 for api::SchemaError #876

Merged
merged 12 commits into from
May 28, 2024
Merged

Implement #745 for api::SchemaError #876

merged 12 commits into from
May 28, 2024

Conversation

shaobo-he-aws
Copy link
Contributor

@shaobo-he-aws shaobo-he-aws commented May 15, 2024

Description of changes

This PR also changes the signature of the validator's SchemaError.

Issue #, if available

#745

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).

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).

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.

Signed-off-by: Shaobo He <shaobohe@amazon.com>
cedar-policy/src/api/err.rs Outdated Show resolved Hide resolved
cedar-policy/src/api/err.rs Outdated Show resolved Hide resolved
cedar-policy-validator/src/err.rs Show resolved Hide resolved
Signed-off-by: Shaobo He <shaobohe@amazon.com>
Signed-off-by: Shaobo He <shaobohe@amazon.com>
Signed-off-by: Shaobo He <shaobohe@amazon.com>
Signed-off-by: Shaobo He <shaobohe@amazon.com>
Copy link
Contributor

@aaronjeline aaronjeline left a comment

Choose a reason for hiding this comment

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

Agree with johns comment

cedar-policy/src/api/err.rs Outdated Show resolved Hide resolved
cedar-policy/src/api/err.rs Outdated Show resolved Hide resolved
cedar-policy/src/api/err.rs Outdated Show resolved Hide resolved
cedar-policy/src/api/err.rs Outdated Show resolved Hide resolved
Comment on lines 222 to 224
pub fn get_node_in_cycle(&self) -> SmolStr {
self.node.to_smolstr()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to return the EntityUid here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we'd better not expose implementation details here, which include what nodes are.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's sensible for a CycleInActionHierarchyError to have a getter which tells users the EntityUid of the action that was in the cycle. I agree we shouldn't expose implementation details about nodes, but I think returning an EntityUid is much more helpful to users than a string.

cedar-policy/src/api/err.rs Outdated Show resolved Hide resolved
cedar-policy/src/api/err.rs Outdated Show resolved Hide resolved
Signed-off-by: Shaobo He <shaobohe@amazon.com>
Signed-off-by: Shaobo He <shaobohe@amazon.com>
Signed-off-by: Shaobo He <shaobohe@amazon.com>
Signed-off-by: Shaobo He <shaobohe@amazon.com>
@shaobo-he-aws
Copy link
Contributor Author

shaobo-he-aws commented May 24, 2024

Pushed a new design.

  1. Replaced the SchemaError in cedar-policy with the one in cedar-policy-validator. I think it's the best for maintainability, even at the cost of messing up semver checks.
  2. Group all sub-error types of SchemaError in a submodule of err and re-export it in cedar-policy.

A drawback of this design is that we can't write precise getter APIs for sub-error types. For instance, entity UIDs have different types in cedar-policy and cedar-policy-validator.

/// Error thrown by the `serde_json` crate during serialization
#[error(transparent)]
#[diagnostic(transparent)]
// no #[from], because if you just have a serde_json::Error you should choose between JsonDeserialization and JsonSerialization appropriately
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the JsonDeserialization variant also not have #[from]?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Fixed.

Signed-off-by: Shaobo He <shaobohe@amazon.com>
Signed-off-by: Shaobo He <shaobohe@amazon.com>
@shaobo-he-aws shaobo-he-aws merged commit 11ae14a into main May 28, 2024
14 of 17 checks passed
@shaobo-he-aws shaobo-he-aws deleted the chore/shaobo/745 branch May 28, 2024 18:27
shaobo-he-aws added a commit to cedar-policy/cedar-examples that referenced this pull request May 28, 2024
Signed-off-by: Shaobo He <shaobohe@amazon.com>
shaobo-he-aws added a commit to cedar-policy/cedar-spec that referenced this pull request May 28, 2024
Signed-off-by: Shaobo He <shaobohe@amazon.com>
shaobo-he-aws added a commit to cedar-policy/cedar-examples that referenced this pull request May 28, 2024
Signed-off-by: Shaobo He <shaobohe@amazon.com>
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