generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 107
Add help
to some type errors
#513
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shaobo-he-aws
approved these changes
Dec 15, 2023
andrewmwells-amazon
approved these changes
Dec 15, 2023
cdisselkoen
reviewed
Dec 15, 2023
cdisselkoen
approved these changes
Dec 18, 2023
Comment on lines
+483
to
+503
pub(crate) fn suggested_has_guard(&self) -> String { | ||
// We know if this is an access directly on `context`, so we can suggest | ||
// specifically `context has ..`. Otherwise, we just use a generic `e`. | ||
let base_expr = match self { | ||
AttributeAccess::Context(_, _) => "context".into(), | ||
_ => "e".into(), | ||
}; | ||
|
||
let (safe_attrs, err_attr) = match self.attrs().split_first() { | ||
Some((first, rest)) => (rest, first.clone()), | ||
// We should always have a least one attribute stored, so this | ||
// shouldn't be possible. If it does happen, just use a placeholder | ||
// attribute name `f` since we'd rather avoid panicking. | ||
None => (&[] as &[SmolStr], "f".into()), | ||
}; | ||
|
||
let full_expr = std::iter::once(&base_expr) | ||
.chain(safe_attrs.iter().rev()) | ||
.join("."); | ||
format!("{full_expr} has {err_attr}") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is complicated enough that it might make sense to have a test checking that the generated help message is sensible. maybe in particular for a case like context.foo.bar has spam
.
shaobo-he-aws
approved these changes
Dec 18, 2023
shaobo-he-aws
pushed a commit
that referenced
this pull request
May 20, 2025
Signed-off-by: Craig Disselkoen <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of changes
Add help messages on to type errors where we can suggest a useful fix. For example, an error from using
in
with a non-entity on the left will suggest usingcontains
,containsAll
orcontainsAny
instead.Issue #, if available
Checklist for requesting a review
The change in this PR is (choose one, and delete the other options):
cedar-policy
.I confirm that this PR (choose one, and delete the other options):
I confirm that
cedar-spec
(choose one, and delete the other options):Disclaimer
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.