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

Improving error messages #1129

Merged
merged 7 commits into from
Aug 9, 2024
Merged

Improving error messages #1129

merged 7 commits into from
Aug 9, 2024

Conversation

aaronjeline
Copy link
Contributor

@aaronjeline aaronjeline commented Aug 8, 2024

Description of changes

Cleans up two remaining error tasks

  • EntityUid::from_json returns a concrete type instead of an existential
  • CedarSchemaError::Parse is more transparent

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

  • Does not update the CHANGELOG because my change does not significantly impact released code.

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.

@aaronjeline aaronjeline mentioned this pull request Aug 8, 2024
3 tasks
Copy link
Contributor

@cdisselkoen cdisselkoen left a comment

Choose a reason for hiding this comment

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

Minor nits

cedar-policy-validator/src/cedar_schema/err.rs Outdated Show resolved Hide resolved
cedar-policy-validator/src/cedar_schema/err.rs Outdated Show resolved Hide resolved
cedar-policy-validator/src/cedar_schema/err.rs Outdated Show resolved Hide resolved
cedar-policy-validator/src/cedar_schema/to_json_schema.rs Outdated Show resolved Hide resolved
cedar-policy-validator/src/err.rs Outdated Show resolved Hide resolved
cedar-policy-validator/src/err.rs Outdated Show resolved Hide resolved
Signed-off-by: Aaron Eline <aeline+github@amazon.com>
Signed-off-by: Aaron Eline <aeline+github@amazon.com>
Signed-off-by: Aaron Eline <aeline+github@amazon.com>
Signed-off-by: Aaron Eline <aeline+github@amazon.com>
Signed-off-by: Aaron Eline <aeline+github@amazon.com>
@aaronjeline
Copy link
Contributor Author

Semver checks expected to fail

@aaronjeline aaronjeline marked this pull request as ready for review August 8, 2024 20:26
@shaobo-he-aws
Copy link
Contributor

It seems this PR overlaps with #1130. I'll close that one in favor this PR.

Signed-off-by: Aaron Eline <aeline+github@amazon.com>
@@ -201,6 +204,15 @@ impl Display for ParseErrors {
}
}

impl IntoIterator for ParseErrors {
type Item = ParseError;
type IntoIter = Chain<Once<ParseError>, vec::IntoIter<ParseError>>;
Copy link
Contributor

Choose a reason for hiding this comment

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

What's an idiomatic type we should use here? The current one seems overly complicated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Eh it's a combination of types that are all in the stdlib. Unless we want to re-implement the underlying iterators this seems like the best.

Copy link
Contributor

Choose a reason for hiding this comment

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

Another option is type IntoIter = <NonEmpty as IntoIterator>::IntoIter;

Copy link
Contributor

Choose a reason for hiding this comment

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

If this is part of our public API then I think we should expose a nicer iterator type. In other parts of our API we use a wrapper struct that holds the actual iter in a private field.

@@ -250,14 +262,19 @@ impl Diagnostic for ParseErrors {
}
}

/// Collection of [`ToJsonSchemaError`]
/// This collection is guaranteed (by construction) to have at least one error.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: remove this and change the above line to Non-empty collection of ....

#[error(transparent)]
#[diagnostic(transparent)]
DuplicateContext(DuplicateContext),
/// Error raised when a `principal` or `resource` is declared twice
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: twice to multiple times.

Copy link
Contributor

@shaobo-he-aws shaobo-he-aws left a comment

Choose a reason for hiding this comment

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

LGTM.

cedar-policy-validator/src/cedar_schema/err.rs Outdated Show resolved Hide resolved
cedar-policy-validator/src/cedar_schema/err.rs Outdated Show resolved Hide resolved
cedar-policy-validator/src/cedar_schema/err.rs Outdated Show resolved Hide resolved
Signed-off-by: Aaron Eline <aeline+github@amazon.com>
@aaronjeline aaronjeline requested a review from cdisselkoen August 9, 2024 13:52
@aaronjeline aaronjeline merged commit 6b516d4 into main Aug 9, 2024
18 of 19 checks passed
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.

5 participants