-
Notifications
You must be signed in to change notification settings - Fork 88
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
miette
integration for all errors in Core, Validator, and cedar-policy
#477
Conversation
cedar-policy-core/src/est/err.rs
Outdated
#[error("invalid escape patterns: {:?}", .0.iter().map(|e| e.to_string()).collect::<Vec<String>>())] | ||
UnescapeError(Vec<unescape::UnescapeError>), | ||
UnescapeError(#[related] Vec<unescape::UnescapeError>), |
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.
Can we make the error just invalid escape pattern
and rely on #[related]
to aggregate the errors?
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.
We could. Or we could just show the first error message in the #[error]
, like we do for parse errors. In #326 we decided not to totally kneecap the Display
for ParseErrors
in case users are only looking at the Display
. We could revisit that decision, or decide differently here. Do you have a preference between no error message / first error message / all error messages?
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.
It doesn't bother me too much. Using the {:?}
debug formatting in error messages doesn't always work out well, but if it formats nicely in this case it's fine
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.
Fixed this up some, including the error message in unescape::UnescapeError
itself
cedar-policy-validator/src/err.rs
Outdated
UndeclaredActions(HashSet<String>), | ||
/// Undeclared common type(s) used in entity or context attributes. | ||
#[error("undeclared common type(s): {0:?}")] | ||
#[diagnostic(help("any common types used in entity or context attributes need to be declared in `commonTypes`"))] |
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.
#[diagnostic(help("any common types used in entity or context attributes need to be declared in `commonTypes`"))] | |
#[diagnostic(help("any common types used in entity or context attributes need to be declared in `commonTypes`, and common types may not reference other common types"))] |
We could do more to make the error in this case nice, but this at least helps
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.
is this the error we get if we try to have common types reference other common types?
if so I can update the doc comment on the variant as well
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.
That'd be good
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.
Updated
Description of changes
Derives (or manually implements)
miette::Diagnostic
for all our error types. Tries to make good use of thehelp()
field, but does not yet assign error codes or propagate source locations; those can be done in followup PRs (and have their own GitHub issues).No breaking changes to the public API. Some error messages have changed, and in particular, in some cases, information that used to be in the
Display
for an error is now in othermiette
fields. I have updated the CHANGELOG with a note about this. I'm not sure where else we should document it.To display a
miette::Diagnostic
in a pretty fashion, convert it tomiette::Report
usingFrom
/Into
. Note that?
automatically converts errors, so it is sufficient to declare the error type of your function (ormain()
) asmiette::Report
. Note also that you need thefancy
feature ofmiette
for prettiest output; we enable this in the CLI crate but not in our library crates, as recommended bymiette
. ("You should only [enable the"fancy"
feature] in your toplevel crate, as the fancy feature pulls in a number of dependencies that libraries and such might not want.")Sample outputs from the CLI:
Issue #, if available
Resolves #182
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.